Package org.jmol.adapter.readers.cif
Class MessagePackReader
- java.lang.Object
-
- org.jmol.adapter.readers.cif.MessagePackReader
-
public class MessagePackReader extends java.lang.ObjectA 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
-
-
Field Summary
Fields Modifier and Type Field Description private static intARRAY16private static intARRAY32private static intBIN16private static intBIN32private static intBIN8private static intDEFINITE_xE0private javajs.api.GenericBinaryDocumentdocprivate static intEXT16private static intEXT32private static intEXT8private static intFALSEprivate static intFIXEXT1private static intFIXEXT16private static intFIXEXT2private static intFIXEXT4private static intFIXEXT8private static intFIXMAP_xF0private static intFIXSTR_xE0private static intFLOAT32private static intFLOAT64private static intINT16private static intINT32private static intINT64private static intINT8private booleanisHomoprivate static intMAP16private static intMAP32private static intNEGATIVEFIXINT_xE0private static intNILprivate static intPOSITIVEFIXINT_x80private static intSTR16private static intSTR32private static intSTR8private static intTRUEprivate static intUINT16private static intUINT32private static intUINT64private static intUINT8
-
Constructor Summary
Constructors Constructor Description MessagePackReader(javajs.api.GenericBinaryDocument binaryDoc, boolean isHomogeneousArrays)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Objectdecode(byte[] b)This single method takes care of all MMTF needs.private java.lang.ObjectgetArray(int n)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.private java.lang.ObjectgetMap(int n)java.lang.ObjectgetNext(java.lang.Object array, int pt)java.util.Map<java.lang.String,java.lang.Object>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 java.lang.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.
-
-
-
Field Detail
-
doc
private javajs.api.GenericBinaryDocument doc
-
isHomo
private boolean isHomo
-
POSITIVEFIXINT_x80
private static final int POSITIVEFIXINT_x80
- See Also:
- Constant Field Values
-
FIXMAP_xF0
private static final int FIXMAP_xF0
- See Also:
- Constant Field Values
-
FIXSTR_xE0
private static final int FIXSTR_xE0
- See Also:
- Constant Field Values
-
NEGATIVEFIXINT_xE0
private static final int NEGATIVEFIXINT_xE0
- See Also:
- Constant Field Values
-
DEFINITE_xE0
private static final int DEFINITE_xE0
- See Also:
- Constant Field Values
-
NIL
private static final int NIL
- See Also:
- Constant Field Values
-
FALSE
private static final int FALSE
- See Also:
- Constant Field Values
-
TRUE
private static final int TRUE
- See Also:
- Constant Field Values
-
BIN8
private static final int BIN8
- See Also:
- Constant Field Values
-
BIN16
private static final int BIN16
- See Also:
- Constant Field Values
-
BIN32
private static final int BIN32
- See Also:
- Constant Field Values
-
EXT8
private static final int EXT8
- See Also:
- Constant Field Values
-
EXT16
private static final int EXT16
- See Also:
- Constant Field Values
-
EXT32
private static final int EXT32
- See Also:
- Constant Field Values
-
FLOAT32
private static final int FLOAT32
- See Also:
- Constant Field Values
-
FLOAT64
private static final int FLOAT64
- See Also:
- Constant Field Values
-
UINT8
private static final int UINT8
- See Also:
- Constant Field Values
-
UINT16
private static final int UINT16
- See Also:
- Constant Field Values
-
UINT32
private static final int UINT32
- See Also:
- Constant Field Values
-
UINT64
private static final int UINT64
- See Also:
- Constant Field Values
-
INT8
private static final int INT8
- See Also:
- Constant Field Values
-
INT16
private static final int INT16
- See Also:
- Constant Field Values
-
INT32
private static final int INT32
- See Also:
- Constant Field Values
-
INT64
private static final int INT64
- See Also:
- Constant Field Values
-
FIXEXT1
private static final int FIXEXT1
- See Also:
- Constant Field Values
-
FIXEXT2
private static final int FIXEXT2
- See Also:
- Constant Field Values
-
FIXEXT4
private static final int FIXEXT4
- See Also:
- Constant Field Values
-
FIXEXT8
private static final int FIXEXT8
- See Also:
- Constant Field Values
-
FIXEXT16
private static final int FIXEXT16
- See Also:
- Constant Field Values
-
STR8
private static final int STR8
- See Also:
- Constant Field Values
-
STR16
private static final int STR16
- See Also:
- Constant Field Values
-
STR32
private static final int STR32
- See Also:
- Constant Field Values
-
ARRAY16
private static final int ARRAY16
- See Also:
- Constant Field Values
-
ARRAY32
private static final int ARRAY32
- See Also:
- Constant Field Values
-
MAP16
private static final int MAP16
- See Also:
- Constant Field Values
-
MAP32
private static final int MAP32
- See Also:
- Constant Field Values
-
-
Method Detail
-
readMap
public java.util.Map<java.lang.String,java.lang.Object> readMap() throws java.lang.Exception- Throws:
java.lang.Exception
-
getNext
public java.lang.Object getNext(java.lang.Object array, int pt) throws java.lang.Exception- Throws:
java.lang.Exception
-
getArray
private java.lang.Object getArray(int n) throws java.lang.Exception- Throws:
java.lang.Exception
-
getMap
private java.lang.Object getMap(int n) throws java.lang.Exception- Throws:
java.lang.Exception
-
decode
public static java.lang.Object decode(byte[] b)
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
public static java.lang.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.- 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
-
-