Last active
August 11, 2017 21:40
-
-
Save dgreenshtein/07398b1bb6607326851cc839b431c2ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.hbase.util; | |
import org.apache.hadoop.hbase.util.Order; | |
import org.apache.hadoop.hbase.util.OrderedBytes; | |
import org.apache.hadoop.hbase.util.PositionedByteRange; | |
import org.apache.hadoop.hbase.util.SimplePositionedByteRange; | |
public class EncodingUtil { | |
public static byte[] encodeDouble(double valueToEncode, int length) { | |
byte[] internal = new byte[length + 3]; | |
PositionedByteRange byteRange = new SimplePositionedByteRange(internal, 1, length + 1); | |
byteRange.setPosition(1); | |
OrderedBytes.encodeNumeric(byteRange, valueToEncode, Order.ASCENDING); | |
return byteRange.getBytes(); | |
} | |
public static double decodeDouble(byte[] valueToDecode, int length) { | |
PositionedByteRange byteRange = new SimplePositionedByteRange(valueToDecode, 1, length + 1); | |
byteRange.setPosition(1); | |
return OrderedBytes.decodeNumericAsDouble(byteRange); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment