Package javajs.util
Class MessagePackReader
java.lang.Object
javajs.util.MessagePackReader
A simple MessagePack reader. See https://github.com/msgpack/msgpack/blob/master/spec.md
with very few dependencies.
Nuances:
Does not implement unsigned int32 or int64 (delivers simple integers in all cases).
Does not use doubles; just floats
Note:
homogeneousArrays == true will deliver null for empty array.
Use in MMTF:
BufferedInputStream bs = [whatever]
GenericBinaryDocument binaryDoc = new javajs.util.BinaryDocument();
binaryDoc.setStream(bs, true);
map = (new MessagePackReader(binaryDoc, true)).readMap();
entities = (Object[]) map.get("entityList");
float[] x = (float[]) decode((byte[]) map.get("xCoordList"))
- Author:
- Bob Hanson hansonr@stolaf.edu
-
Constructor Summary
ConstructorsConstructorDescriptionMessagePackReader
(GenericBinaryDocumentReader binaryDoc, boolean isHomogeneousArrays) -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
decode
(byte[] b) This single method takes care of all MMTF needs.static float[]
getFloats
(byte[] b, int n, float divisor) mmtf type 1 and 11 byte[4] to float32static int[]
getInts
(byte[] b, int n) mmtf types 2-4 Decode a byte array into a byte, short, or int array.readMap()
static int[]
rldecode32
(byte[] b, int n) mmtf type 7 Decode an array of int32 using run-length decoding.static int[]
rldecode32Delta
(byte[] b, int n) mmtf type 8 Decode an array of int32 using run-length decoding of a difference array.static char[]
rldecode32ToChar
(byte[] b, int n) mmtf type 6 Decode an array of int32 using run-length decoding to one char per int.static String[]
rldecode32ToStr
(byte[] b) mmtf type 5 Decode each four bytes as a 1- to 4-character string label where a 0 byte indicates end-of-string.static float[]
rldecodef
(byte[] b, int n, float divisor) mmtf type 9 Decode an array of int32 using run-length decoding and divide by a divisor to give a float32.static int[]
unpack
(byte[] b, int nBytes, int n) mmtf type 14 and 15 Unpack an array of int8 or int16 to int32.static float[]
unpack16Deltaf
(byte[] b, int n, float divisor) mmtf type 10 Decode an array of int16 using run-length decoding of a difference array.static float[]
unpackf
(byte[] b, int nBytes, int n, float divisor) mmtf type 12 and 13 Unpack an array of int8 or int16 to int32 and divide to give a float32.
-
Constructor Details
-
MessagePackReader
-
MessagePackReader
public MessagePackReader()
-
-
Method Details
-
getMapForStream
- Throws:
Exception
-
readMap
- Throws:
Exception
-
getNext
- Throws:
Exception
-
decode
This single method takes care of all MMTF needs. See https://github.com/rcsb/mmtf/blob/master/spec.md- Parameters:
b
-- Returns:
- array of int, char, or float, depending upon the type
-
getFloats
public static float[] getFloats(byte[] b, int n, float divisor) mmtf type 1 and 11 byte[4] to float32- Parameters:
b
-n
-divisor
-- Returns:
- array of floats
-
getInts
public static int[] getInts(byte[] b, int n) mmtf types 2-4 Decode a byte array into a byte, short, or int array.- Parameters:
b
-n
-- Returns:
- array of integers
-
rldecode32ToStr
mmtf type 5 Decode each four bytes as a 1- to 4-character string label where a 0 byte indicates end-of-string.- Parameters:
b
- a byte array- Returns:
- String[]
-
rldecode32ToChar
public static char[] rldecode32ToChar(byte[] b, int n) mmtf type 6 Decode an array of int32 using run-length decoding to one char per int.- Parameters:
b
-n
-- Returns:
- array of characters
-
rldecode32
public static int[] rldecode32(byte[] b, int n) mmtf type 7 Decode an array of int32 using run-length decoding.- Parameters:
b
-n
-- Returns:
- array of integers
-
rldecode32Delta
public static int[] rldecode32Delta(byte[] b, int n) mmtf type 8 Decode an array of int32 using run-length decoding of a difference array.- Parameters:
b
-n
-- Returns:
- array of integers
-
rldecodef
public static float[] rldecodef(byte[] b, int n, float divisor) mmtf type 9 Decode an array of int32 using run-length decoding and divide by a divisor to give a float32.- Parameters:
b
-n
-divisor
-- Returns:
- array of floats
-
unpack16Deltaf
public static float[] unpack16Deltaf(byte[] b, int n, float divisor) mmtf type 10 Decode an array of int16 using run-length decoding of a difference array.- Parameters:
b
-n
-divisor
-- Returns:
- array of floats
-
unpackf
public static float[] unpackf(byte[] b, int nBytes, int n, float divisor) mmtf type 12 and 13 Unpack an array of int8 or int16 to int32 and divide to give a float32. untested- Parameters:
b
-nBytes
-n
-divisor
-- Returns:
- array of floats
-
unpack
public static int[] unpack(byte[] b, int nBytes, int n) mmtf type 14 and 15 Unpack an array of int8 or int16 to int32. untested- Parameters:
b
-nBytes
-n
-- Returns:
- array of integers
-