Skip to content

Instantly share code, notes, and snippets.

@dgreenshtein
Last active August 11, 2017 21:40
Show Gist options
  • Save dgreenshtein/07398b1bb6607326851cc839b431c2ac to your computer and use it in GitHub Desktop.
Save dgreenshtein/07398b1bb6607326851cc839b431c2ac to your computer and use it in GitHub Desktop.
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