false
value (encoded as "simple value": {@link #MT_SIMPLE}). */
+ int FALSE = 0x14;
+ /** The CBOR-encoded boolean true
value (encoded as "simple value": {@link #MT_SIMPLE}). */
+ int TRUE = 0x15;
+ /** The CBOR-encoded null
value (encoded as "simple value": {@link #MT_SIMPLE}). */
+ int NULL = 0x16;
+ /** The CBOR-encoded "undefined" value (encoded as "simple value": {@link #MT_SIMPLE}). */
+ int UNDEFINED = 0x17;
+ /** Denotes a half-precision float (two-byte IEEE 754, see {@link #MT_FLOAT}). */
+ int HALF_PRECISION_FLOAT = 0x19;
+ /** Denotes a single-precision float (four-byte IEEE 754, see {@link #MT_FLOAT}). */
+ int SINGLE_PRECISION_FLOAT = 0x1a;
+ /** Denotes a double-precision float (eight-byte IEEE 754, see {@link #MT_FLOAT}). */
+ int DOUBLE_PRECISION_FLOAT = 0x1b;
+ /** The CBOR-encoded "break" stop code for unlimited arrays/maps. */
+ int BREAK = 0x1f;
+
+ /** Semantic tag value describing date/time values in the standard format (UTF8 string, RFC3339). */
+ int TAG_STANDARD_DATE_TIME = 0;
+ /** Semantic tag value describing date/time values as Epoch timestamp (numeric, RFC3339). */
+ int TAG_EPOCH_DATE_TIME = 1;
+ /** Semantic tag value describing a positive big integer value (byte string). */
+ int TAG_POSITIVE_BIGINT = 2;
+ /** Semantic tag value describing a negative big integer value (byte string). */
+ int TAG_NEGATIVE_BIGINT = 3;
+ /** Semantic tag value describing a decimal fraction value (two-element array, base 10). */
+ int TAG_DECIMAL_FRACTION = 4;
+ /** Semantic tag value describing a big decimal value (two-element array, base 2). */
+ int TAG_BIGDECIMAL = 5;
+ /** Semantic tag value describing an expected conversion to base64url encoding. */
+ int TAG_EXPECTED_BASE64_URL_ENCODED = 21;
+ /** Semantic tag value describing an expected conversion to base64 encoding. */
+ int TAG_EXPECTED_BASE64_ENCODED = 22;
+ /** Semantic tag value describing an expected conversion to base16 encoding. */
+ int TAG_EXPECTED_BASE16_ENCODED = 23;
+ /** Semantic tag value describing an encoded CBOR data item (byte string). */
+ int TAG_CBOR_ENCODED = 24;
+ /** Semantic tag value describing an URL (UTF8 string). */
+ int TAG_URI = 32;
+ /** Semantic tag value describing a base64url encoded string (UTF8 string). */
+ int TAG_BASE64_URL_ENCODED = 33;
+ /** Semantic tag value describing a base64 encoded string (UTF8 string). */
+ int TAG_BASE64_ENCODED = 34;
+ /** Semantic tag value describing a regular expression string (UTF8 string, PCRE). */
+ int TAG_REGEXP = 35;
+ /** Semantic tag value describing a MIME message (UTF8 string, RFC2045). */
+ int TAG_MIME_MESSAGE = 36;
+ /** Semantic tag value describing CBOR content. */
+ int TAG_CBOR_MARKER = 55799;
+}
diff --git a/plugins/com.minres.scviewer.database.ftr/src/jacob/CborDecoder.java b/plugins/com.minres.scviewer.database.ftr/src/jacob/CborDecoder.java
new file mode 100644
index 0000000..b7b6433
--- /dev/null
+++ b/plugins/com.minres.scviewer.database.ftr/src/jacob/CborDecoder.java
@@ -0,0 +1,515 @@
+/*
+ * JACOB - CBOR implementation in Java.
+ *
+ * (C) Copyright - 2013 - J.W. Janssen null
.
+ */
+ public CborDecoder(InputStream is) {
+ if (is == null) {
+ throw new IllegalArgumentException("InputStream cannot be null!");
+ }
+ m_is = (is instanceof PushbackInputStream) ? (PushbackInputStream) is : new PushbackInputStream(is);
+ total_avail = getAvailableBytes(m_is);
+ }
+
+ private static void fail(String msg, Object... args) throws IOException {
+ throw new IOException(String.format(msg, args));
+ }
+
+ private static String lengthToString(int len) {
+ return (len < 0) ? "no payload" : (len == ONE_BYTE) ? "one byte" : (len == TWO_BYTES) ? "two bytes"
+ : (len == FOUR_BYTES) ? "four bytes" : (len == EIGHT_BYTES) ? "eight bytes" : "(unknown)";
+ }
+
+ public long getPos() {
+ try {
+ return total_avail-m_is.available();
+ } catch (IOException e) {
+ return -1;
+ }
+ }
+ /**
+ * Peeks in the input stream for the upcoming type.
+ *
+ * @return the upcoming type in the stream, or null
in case of an end-of-stream.
+ * @throws IOException in case of I/O problems reading the CBOR-type from the underlying input stream.
+ */
+ public CborType peekType() throws IOException {
+ int p = m_is.read();
+ if (p < 0) {
+ // EOF, nothing to peek at...
+ return null;
+ }
+ m_is.unread(p);
+ return valueOf(p);
+ }
+
+ /**
+ * Prolog to reading an array value in CBOR format.
+ *
+ * @return the number of elements in the array to read, or -1 in case of infinite-length arrays.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public long readArrayLength() throws IOException {
+ return readMajorTypeWithSize(TYPE_ARRAY);
+ }
+
+ /**
+ * Reads a boolean value in CBOR format.
+ *
+ * @return the read boolean.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public boolean readBoolean() throws IOException {
+ int b = readMajorType(TYPE_FLOAT_SIMPLE);
+ if (b != FALSE && b != TRUE) {
+ fail("Unexpected boolean value: %d!", b);
+ }
+ return b == TRUE;
+ }
+
+ /**
+ * Reads a "break"/stop value in CBOR format.
+ *
+ * @return always null
.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public Object readBreak() throws IOException {
+ readMajorTypeExact(TYPE_FLOAT_SIMPLE, BREAK);
+
+ return null;
+ }
+
+ /**
+ * Reads a byte string value in CBOR format.
+ *
+ * @return the read byte string, never null
. In case the encoded string has a length of 0, an empty string is returned.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public byte[] readByteString() throws IOException {
+ long len = readMajorTypeWithSize(TYPE_BYTE_STRING);
+ if (len < 0) {
+ fail("Infinite-length byte strings not supported!");
+ }
+ if (len > Integer.MAX_VALUE) {
+ fail("String length too long!");
+ }
+ return readFully(new byte[(int) len]);
+ }
+
+ /**
+ * Prolog to reading a byte string value in CBOR format.
+ *
+ * @return the number of bytes in the string to read, or -1 in case of infinite-length strings.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public long readByteStringLength() throws IOException {
+ return readMajorTypeWithSize(TYPE_BYTE_STRING);
+ }
+
+ /**
+ * Reads a double-precision float value in CBOR format.
+ *
+ * @return the read double value, values from {@link Float#MIN_VALUE} to {@link Float#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public double readDouble() throws IOException {
+ readMajorTypeExact(TYPE_FLOAT_SIMPLE, DOUBLE_PRECISION_FLOAT);
+
+ return Double.longBitsToDouble(readUInt64());
+ }
+
+ /**
+ * Reads a single-precision float value in CBOR format.
+ *
+ * @return the read float value, values from {@link Float#MIN_VALUE} to {@link Float#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public float readFloat() throws IOException {
+ readMajorTypeExact(TYPE_FLOAT_SIMPLE, SINGLE_PRECISION_FLOAT);
+
+ return Float.intBitsToFloat((int) readUInt32());
+ }
+
+ /**
+ * Reads a half-precision float value in CBOR format.
+ *
+ * @return the read half-precision float value, values from {@link Float#MIN_VALUE} to {@link Float#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public double readHalfPrecisionFloat() throws IOException {
+ readMajorTypeExact(TYPE_FLOAT_SIMPLE, HALF_PRECISION_FLOAT);
+
+ int half = readUInt16();
+ int exp = (half >> 10) & 0x1f;
+ int mant = half & 0x3ff;
+
+ double val;
+ if (exp == 0) {
+ val = mant * Math.pow(2, -24);
+ } else if (exp != 31) {
+ val = (mant + 1024) * Math.pow(2, exp - 25);
+ } else if (mant != 0) {
+ val = Double.NaN;
+ } else {
+ val = Double.POSITIVE_INFINITY;
+ }
+
+ return ((half & 0x8000) == 0) ? val : -val;
+ }
+
+ /**
+ * Reads a signed or unsigned integer value in CBOR format.
+ *
+ * @return the read integer value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public long readInt() throws IOException {
+ int ib = m_is.read();
+
+ // in case of negative integers, extends the sign to all bits; otherwise zero...
+ long ui = expectIntegerType(ib);
+ // in case of negative integers does a ones complement
+ return ui ^ readUInt(ib & 0x1f, false /* breakAllowed */);
+ }
+
+ /**
+ * Reads a signed or unsigned 16-bit integer value in CBOR format.
+ *
+ * @read the small integer value, values from [-65536..65535] are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
+ */
+ public int readInt16() throws IOException {
+ int ib = m_is.read();
+
+ // in case of negative integers, extends the sign to all bits; otherwise zero...
+ long ui = expectIntegerType(ib);
+ // in case of negative integers does a ones complement
+ return (int) (ui ^ readUIntExact(TWO_BYTES, ib & 0x1f));
+ }
+
+ /**
+ * Reads a signed or unsigned 32-bit integer value in CBOR format.
+ *
+ * @read the small integer value, values in the range [-4294967296..4294967295] are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
+ */
+ public long readInt32() throws IOException {
+ int ib = m_is.read();
+
+ // in case of negative integers, extends the sign to all bits; otherwise zero...
+ long ui = expectIntegerType(ib);
+ // in case of negative integers does a ones complement
+ return ui ^ readUIntExact(FOUR_BYTES, ib & 0x1f);
+ }
+
+ /**
+ * Reads a signed or unsigned 64-bit integer value in CBOR format.
+ *
+ * @read the small integer value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
+ */
+ public long readInt64() throws IOException {
+ int ib = m_is.read();
+
+ // in case of negative integers, extends the sign to all bits; otherwise zero...
+ long ui = expectIntegerType(ib);
+ // in case of negative integers does a ones complement
+ return ui ^ readUIntExact(EIGHT_BYTES, ib & 0x1f);
+ }
+
+ /**
+ * Reads a signed or unsigned 8-bit integer value in CBOR format.
+ *
+ * @read the small integer value, values in the range [-256..255] are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
+ */
+ public int readInt8() throws IOException {
+ int ib = m_is.read();
+
+ // in case of negative integers, extends the sign to all bits; otherwise zero...
+ long ui = expectIntegerType(ib);
+ // in case of negative integers does a ones complement
+ return (int) (ui ^ readUIntExact(ONE_BYTE, ib & 0x1f));
+ }
+
+ /**
+ * Prolog to reading a map of key-value pairs in CBOR format.
+ *
+ * @return the number of entries in the map, >= 0.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public long readMapLength() throws IOException {
+ return readMajorTypeWithSize(TYPE_MAP);
+ }
+
+ /**
+ * Reads a null
-value in CBOR format.
+ *
+ * @return always null
.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public Object readNull() throws IOException {
+ readMajorTypeExact(TYPE_FLOAT_SIMPLE, NULL);
+ return null;
+ }
+
+ /**
+ * Reads a single byte value in CBOR format.
+ *
+ * @return the read byte value.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public byte readSimpleValue() throws IOException {
+ readMajorTypeExact(TYPE_FLOAT_SIMPLE, ONE_BYTE);
+ return (byte) readUInt8();
+ }
+
+ /**
+ * Reads a signed or unsigned small (<= 23) integer value in CBOR format.
+ *
+ * @read the small integer value, values in the range [-24..23] are supported.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying output stream.
+ */
+ public int readSmallInt() throws IOException {
+ int ib = m_is.read();
+
+ // in case of negative integers, extends the sign to all bits; otherwise zero...
+ long ui = expectIntegerType(ib);
+ // in case of negative integers does a ones complement
+ return (int) (ui ^ readUIntExact(-1, ib & 0x1f));
+ }
+
+ /**
+ * Reads a semantic tag value in CBOR format.
+ *
+ * @return the read tag value.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public long readTag() throws IOException {
+ return readUInt(readMajorType(TYPE_TAG), false /* breakAllowed */);
+ }
+
+ /**
+ * Reads an UTF-8 encoded string value in CBOR format.
+ *
+ * @return the read UTF-8 encoded string, never null
. In case the encoded string has a length of 0, an empty string is returned.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public String readTextString() throws IOException {
+ long len = readMajorTypeWithSize(TYPE_TEXT_STRING);
+ if (len < 0) {
+ fail("Infinite-length text strings not supported!");
+ }
+ if (len > Integer.MAX_VALUE) {
+ fail("String length too long!");
+ }
+ return new String(readFully(new byte[(int) len]), "UTF-8");
+ }
+
+ /**
+ * Prolog to reading an UTF-8 encoded string value in CBOR format.
+ *
+ * @return the length of the string to read, or -1 in case of infinite-length strings.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public long readTextStringLength() throws IOException {
+ return readMajorTypeWithSize(TYPE_TEXT_STRING);
+ }
+
+ /**
+ * Reads an undefined value in CBOR format.
+ *
+ * @return always null
.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ public Object readUndefined() throws IOException {
+ readMajorTypeExact(TYPE_FLOAT_SIMPLE, UNDEFINED);
+ return null;
+ }
+
+ /**
+ * Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.
+ *
+ * @param majorType the expected major type, cannot be null
(unchecked).
+ * @return either -1 if the major type was an signed integer, or 0 otherwise.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ protected long expectIntegerType(int ib) throws IOException {
+ int majorType = ((ib & 0xFF) >>> 5);
+ if ((majorType != TYPE_UNSIGNED_INTEGER) && (majorType != TYPE_NEGATIVE_INTEGER)) {
+ fail("Unexpected type: %s, expected type %s or %s!", getName(majorType), getName(TYPE_UNSIGNED_INTEGER),
+ getName(TYPE_NEGATIVE_INTEGER));
+ }
+ return -majorType;
+ }
+
+ /**
+ * Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.
+ *
+ * @param majorType the expected major type, cannot be null
(unchecked).
+ * @return the read subtype, or payload, of the read major type.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ protected int readMajorType(int majorType) throws IOException {
+ int ib = m_is.read();
+ if (majorType != ((ib >>> 5) & 0x07)) {
+ fail("Unexpected type: %s, expected: %s!", getName(ib), getName(majorType));
+ }
+ return ib & 0x1F;
+ }
+
+ /**
+ * Reads the next major type from the underlying input stream, and verifies whether it matches the given expectations.
+ *
+ * @param majorType the expected major type, cannot be null
(unchecked);
+ * @param subtype the expected subtype.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ protected void readMajorTypeExact(int majorType, int subtype) throws IOException {
+ int st = readMajorType(majorType);
+ if ((st ^ subtype) != 0) {
+ fail("Unexpected subtype: %d, expected: %d!", st, subtype);
+ }
+ }
+
+ /**
+ * Reads the next major type from the underlying input stream, verifies whether it matches the given expectation, and decodes the payload into a size.
+ *
+ * @param majorType the expected major type, cannot be null
(unchecked).
+ * @return the number of succeeding bytes, >= 0, or -1 if an infinite-length type is read.
+ * @throws IOException in case of I/O problems reading the CBOR-encoded value from the underlying input stream.
+ */
+ protected long readMajorTypeWithSize(int majorType) throws IOException {
+ return readUInt(readMajorType(majorType), true /* breakAllowed */);
+ }
+
+ /**
+ * Reads an unsigned integer with a given length-indicator.
+ *
+ * @param length the length indicator to use;
+ * @return the read unsigned integer, as long value.
+ * @throws IOException in case of I/O problems reading the unsigned integer from the underlying input stream.
+ */
+ protected long readUInt(int length, boolean breakAllowed) throws IOException {
+ long result = -1;
+ if (length < ONE_BYTE) {
+ result = length;
+ } else if (length == ONE_BYTE) {
+ result = readUInt8();
+ } else if (length == TWO_BYTES) {
+ result = readUInt16();
+ } else if (length == FOUR_BYTES) {
+ result = readUInt32();
+ } else if (length == EIGHT_BYTES) {
+ result = readUInt64();
+ } else if (breakAllowed && length == BREAK) {
+ return -1;
+ }
+ if (result < 0) {
+ fail("Not well-formed CBOR integer found, invalid length: %d!", result);
+ }
+ return result;
+ }
+
+ /**
+ * Reads an unsigned 16-bit integer value
+ *
+ * @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected int readUInt16() throws IOException {
+ byte[] buf = readFully(new byte[2]);
+ return (buf[0] & 0xFF) << 8 | (buf[1] & 0xFF);
+ }
+
+ /**
+ * Reads an unsigned 32-bit integer value
+ *
+ * @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected long readUInt32() throws IOException {
+ byte[] buf = readFully(new byte[4]);
+ return ((buf[0] & 0xFF) << 24 | (buf[1] & 0xFF) << 16 | (buf[2] & 0xFF) << 8 | (buf[3] & 0xFF)) & 0xffffffffL;
+ }
+
+ /**
+ * Reads an unsigned 64-bit integer value
+ *
+ * @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected long readUInt64() throws IOException {
+ byte[] buf = readFully(new byte[8]);
+ return (buf[0] & 0xFFL) << 56 | (buf[1] & 0xFFL) << 48 | (buf[2] & 0xFFL) << 40 | (buf[3] & 0xFFL) << 32 | //
+ (buf[4] & 0xFFL) << 24 | (buf[5] & 0xFFL) << 16 | (buf[6] & 0xFFL) << 8 | (buf[7] & 0xFFL);
+ }
+
+ /**
+ * Reads an unsigned 8-bit integer value
+ *
+ * @return value the read value, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected int readUInt8() throws IOException {
+ return m_is.read() & 0xff;
+ }
+
+ /**
+ * Reads an unsigned integer with a given length-indicator.
+ *
+ * @param length the length indicator to use;
+ * @return the read unsigned integer, as long value.
+ * @throws IOException in case of I/O problems reading the unsigned integer from the underlying input stream.
+ */
+ protected long readUIntExact(int expectedLength, int length) throws IOException {
+ if (((expectedLength == -1) && (length >= ONE_BYTE)) || ((expectedLength >= 0) && (length != expectedLength))) {
+ fail("Unexpected payload/length! Expected %s, but got %s.", lengthToString(expectedLength),
+ lengthToString(length));
+ }
+ return readUInt(length, false /* breakAllowed */);
+ }
+
+ private byte[] readFully(byte[] buf) throws IOException {
+ int len = buf.length;
+ int n = 0, off = 0;
+ while (n < len) {
+ int count = m_is.read(buf, off + n, len - n);
+ if (count < 0) {
+ throw new EOFException();
+ }
+ n += count;
+ }
+ return buf;
+ }
+}
diff --git a/plugins/com.minres.scviewer.database.ftr/src/jacob/CborEncoder.java b/plugins/com.minres.scviewer.database.ftr/src/jacob/CborEncoder.java
new file mode 100644
index 0000000..b09aafe
--- /dev/null
+++ b/plugins/com.minres.scviewer.database.ftr/src/jacob/CborEncoder.java
@@ -0,0 +1,488 @@
+/*
+ * JACOB - CBOR implementation in Java.
+ *
+ * (C) Copyright - 2013 - J.W. Janssen null
.
+ */
+ public CborEncoder(OutputStream os) {
+ if (os == null) {
+ throw new IllegalArgumentException("OutputStream cannot be null!");
+ }
+ m_os = os;
+ }
+
+ /**
+ * Interprets a given float-value as a half-precision float value and
+ * converts it to its raw integer form, as defined in IEEE 754.
+ * + * Taken from: this Stack Overflow answer. + *
+ * + * @param fval the value to convert. + * @return the raw integer representation of the given float value. + */ + static int halfPrecisionToRawIntBits(float fval) { + int fbits = Float.floatToIntBits(fval); + int sign = (fbits >>> 16) & 0x8000; + int val = (fbits & 0x7fffffff) + 0x1000; + + // might be or become NaN/Inf + if (val >= 0x47800000) { + if ((fbits & 0x7fffffff) >= 0x47800000) { // is or must become NaN/Inf + if (val < 0x7f800000) { + // was value but too large, make it +/-Inf + return sign | 0x7c00; + } + return sign | 0x7c00 | (fbits & 0x007fffff) >>> 13; // keep NaN (and Inf) bits + } + return sign | 0x7bff; // unrounded not quite Inf + } + if (val >= 0x38800000) { + // remains normalized value + return sign | val - 0x38000000 >>> 13; // exp - 127 + 15 + } + if (val < 0x33000000) { + // too small for subnormal + return sign; // becomes +/-0 + } + + val = (fbits & 0x7fffffff) >>> 23; + // add subnormal bit, round depending on cut off and div by 2^(1-(exp-127+15)) and >> 13 | exp=0 + return sign | ((fbits & 0x7fffff | 0x800000) + (0x800000 >>> val - 102) >>> 126 - val); + } + + /** + * Writes the start of an indefinite-length array. + *
+ * After calling this method, one is expected to write the given number of array elements, which can be of any type. No length checks are performed.
+ * After all array elements are written, one should write a single break value to end the array, see {@link #writeBreak()}.
+ *
+ * After calling this method, one is expected to write the given number of array elements, which can be of any type. No length checks are performed. + *
+ * + * @param length the number of array elements to write, should >= 0. + * @throws IllegalArgumentException in case the given length was negative; + * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream. + */ + public void writeArrayStart(int length) throws IOException { + if (length < 0) { + throw new IllegalArgumentException("Invalid array-length!"); + } + writeType(TYPE_ARRAY, length); + } + + /** + * Writes a boolean value in canonical CBOR format. + * + * @param value the boolean to write. + * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream. + */ + public void writeBoolean(boolean value) throws IOException { + writeSimpleType(TYPE_FLOAT_SIMPLE, value ? TRUE : FALSE); + } + + /** + * Writes a "break" stop-value in canonical CBOR format. + * + * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream. + */ + public void writeBreak() throws IOException { + writeSimpleType(TYPE_FLOAT_SIMPLE, BREAK); + } + + /** + * Writes a byte string in canonical CBOR-format. + * + * @param value the byte string to write, can benull
in which case a byte-string of length 0 is written.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ public void writeByteString(byte[] bytes) throws IOException {
+ writeString(TYPE_BYTE_STRING, bytes);
+ }
+
+ /**
+ * Writes the start of an indefinite-length byte string.
+ *
+ * After calling this method, one is expected to write the given number of string parts. No length checks are performed.
+ * After all string parts are written, one should write a single break value to end the string, see {@link #writeBreak()}.
+ *
+ * After calling this method, one is expected to write any number of map entries, as separate key and value. Keys and values can both be of any type. No length checks are performed.
+ * After all map entries are written, one should write a single break value to end the map, see {@link #writeBreak()}.
+ *
+ * After calling this method, one is expected to write any number of map entries, as separate key and value. Keys and values can both be of any type. No length checks are performed. + *
+ * + * @param length the number of map entries to write, should >= 0. + * @throws IllegalArgumentException in case the given length was negative; + * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream. + */ + public void writeMapStart(int length) throws IOException { + if (length < 0) { + throw new IllegalArgumentException("Invalid length of map!"); + } + writeType(TYPE_MAP, length); + } + + /** + * Writes anull
value in canonical CBOR format.
+ *
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ public void writeNull() throws IOException {
+ writeSimpleType(TYPE_FLOAT_SIMPLE, NULL);
+ }
+
+ /**
+ * Writes a simple value, i.e., an "atom" or "constant" value in canonical CBOR format.
+ *
+ * @param value the (unsigned byte) value to write, values from 32 to 255 are supported (though not enforced).
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ public void writeSimpleValue(byte simpleValue) throws IOException {
+ // convert to unsigned value...
+ int value = (simpleValue & 0xff);
+ writeType(TYPE_FLOAT_SIMPLE, value);
+ }
+
+ /**
+ * Writes a signed or unsigned small (<= 23) integer value in CBOR format.
+ *
+ * @param value the value to write, values in the range [-24..23] are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ public void writeSmallInt(int value) throws IOException {
+ // extends the sign over all bits...
+ int sign = value >> 31;
+ // in case value is negative, this bit should be set...
+ int mt = (int) (sign & NEG_INT_MASK);
+ // complement negative value...
+ value = Math.min(0x17, (sign ^ value));
+
+ m_os.write((int) (mt | value));
+ }
+
+ /**
+ * Writes a semantic tag in canonical CBOR format.
+ *
+ * @param tag the tag to write, should >= 0.
+ * @throws IllegalArgumentException in case the given tag was negative;
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ public void writeTag(long tag) throws IOException {
+ if (tag < 0) {
+ throw new IllegalArgumentException("Invalid tag specification, cannot be negative!");
+ }
+ writeType(TYPE_TAG, tag);
+ }
+
+ /**
+ * Writes an UTF-8 string in canonical CBOR-format.
+ * + * Note that this method is platform specific, as the given string value will be encoded in a byte array + * using the platform encoding! This means that the encoding must be standardized and known. + *
+ * + * @param value the UTF-8 string to write, can benull
in which case an UTF-8 string of length 0 is written.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ public void writeTextString(String value) throws IOException {
+ writeString(TYPE_TEXT_STRING, value == null ? null : value.getBytes("UTF-8"));
+ }
+
+ /**
+ * Writes the start of an indefinite-length UTF-8 string.
+ *
+ * After calling this method, one is expected to write the given number of string parts. No length checks are performed.
+ * After all string parts are written, one should write a single break value to end the string, see {@link #writeBreak()}.
+ *
null
in which case a byte-string of length 0 is written.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected void writeString(int majorType, byte[] bytes) throws IOException {
+ int len = (bytes == null) ? 0 : bytes.length;
+ writeType(majorType, len);
+ for (int i = 0; i < len; i++) {
+ m_os.write(bytes[i]);
+ }
+ }
+
+ /**
+ * Encodes and writes the major type indicator with a given payload (length).
+ *
+ * @param majorType the major type of the value to write, denotes what semantics the written value has;
+ * @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected void writeType(int majorType, long value) throws IOException {
+ writeUInt((majorType << 5), value);
+ }
+
+ /**
+ * Encodes and writes an unsigned integer value, that is, tries to encode it in a little bytes as possible.
+ *
+ * @param mt the major type of the value to write, denotes what semantics the written value has;
+ * @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected void writeUInt(int mt, long value) throws IOException {
+ if (value < 0x18L) {
+ m_os.write((int) (mt | value));
+ } else if (value < 0x100L) {
+ writeUInt8(mt, (int) value);
+ } else if (value < 0x10000L) {
+ writeUInt16(mt, (int) value);
+ } else if (value < 0x100000000L) {
+ writeUInt32(mt, (int) value);
+ } else {
+ writeUInt64(mt, value);
+ }
+ }
+
+ /**
+ * Encodes and writes an unsigned 16-bit integer value
+ *
+ * @param mt the major type of the value to write, denotes what semantics the written value has;
+ * @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected void writeUInt16(int mt, int value) throws IOException {
+ m_os.write(mt | TWO_BYTES);
+ m_os.write(value >> 8);
+ m_os.write(value & 0xFF);
+ }
+
+ /**
+ * Encodes and writes an unsigned 32-bit integer value
+ *
+ * @param mt the major type of the value to write, denotes what semantics the written value has;
+ * @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected void writeUInt32(int mt, int value) throws IOException {
+ m_os.write(mt | FOUR_BYTES);
+ m_os.write(value >> 24);
+ m_os.write(value >> 16);
+ m_os.write(value >> 8);
+ m_os.write(value & 0xFF);
+ }
+
+ /**
+ * Encodes and writes an unsigned 64-bit integer value
+ *
+ * @param mt the major type of the value to write, denotes what semantics the written value has;
+ * @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected void writeUInt64(int mt, long value) throws IOException {
+ m_os.write(mt | EIGHT_BYTES);
+ m_os.write((int) (value >> 56));
+ m_os.write((int) (value >> 48));
+ m_os.write((int) (value >> 40));
+ m_os.write((int) (value >> 32));
+ m_os.write((int) (value >> 24));
+ m_os.write((int) (value >> 16));
+ m_os.write((int) (value >> 8));
+ m_os.write((int) (value & 0xFF));
+ }
+
+ /**
+ * Encodes and writes an unsigned 8-bit integer value
+ *
+ * @param mt the major type of the value to write, denotes what semantics the written value has;
+ * @param value the value to write, values from {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE} are supported.
+ * @throws IOException in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
+ */
+ protected void writeUInt8(int mt, int value) throws IOException {
+ m_os.write(mt | ONE_BYTE);
+ m_os.write(value & 0xFF);
+ }
+}
diff --git a/plugins/com.minres.scviewer.database.ftr/src/jacob/CborType.java b/plugins/com.minres.scviewer.database.ftr/src/jacob/CborType.java
new file mode 100644
index 0000000..70338c1
--- /dev/null
+++ b/plugins/com.minres.scviewer.database.ftr/src/jacob/CborType.java
@@ -0,0 +1,142 @@
+/*
+ * JACOB - CBOR implementation in Java.
+ *
+ * (C) Copyright - 2013 - J.W. Janssen + * The major type is encoded in the upper three bits of each initial byte. The lower 5 bytes represent any additional information. + *
+ */ +public class CborType { + private final int m_major; + private final int m_additional; + + private CborType(int major, int additional) { + m_major = major; + m_additional = additional; + } + + /** + * Returns a descriptive string for the given major type. + * + * @param mt the major type to return as string, values from [0..7] are supported. + * @return the name of the given major type, as String, nevernull
.
+ * @throws IllegalArgumentException in case the given major type is not supported.
+ */
+ public static String getName(int mt) {
+ switch (mt) {
+ case TYPE_ARRAY:
+ return "array";
+ case TYPE_BYTE_STRING:
+ return "byte string";
+ case TYPE_FLOAT_SIMPLE:
+ return "float/simple value";
+ case TYPE_MAP:
+ return "map";
+ case TYPE_NEGATIVE_INTEGER:
+ return "negative integer";
+ case TYPE_TAG:
+ return "tag";
+ case TYPE_TEXT_STRING:
+ return "text string";
+ case TYPE_UNSIGNED_INTEGER:
+ return "unsigned integer";
+ default:
+ throw new IllegalArgumentException("Invalid major type: " + mt);
+ }
+ }
+
+ /**
+ * Decodes a given byte value to a {@link CborType} value.
+ *
+ * @param i the input byte (8-bit) to decode into a {@link CborType} instance.
+ * @return a {@link CborType} instance, never null
.
+ */
+ public static CborType valueOf(int i) {
+ return new CborType((i & 0xff) >>> 5, i & 0x1f);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+
+ CborType other = (CborType) obj;
+ return (m_major == other.m_major) && (m_additional == other.m_additional);
+ }
+
+ /**
+ * @return the additional information of this type, as integer value from [0..31].
+ */
+ public int getAdditionalInfo() {
+ return m_additional;
+ }
+
+ /**
+ * @return the major type, as integer value from [0..7].
+ */
+ public int getMajorType() {
+ return m_major;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + m_additional;
+ result = prime * result + m_major;
+ return result;
+ }
+
+ /**
+ * @return true
if this type allows for an infinite-length payload,
+ * false
if only definite-length payloads are allowed.
+ */
+ public boolean isBreakAllowed() {
+ return m_major == TYPE_ARRAY || m_major == TYPE_BYTE_STRING || m_major == TYPE_MAP
+ || m_major == TYPE_TEXT_STRING;
+ }
+
+ /**
+ * Determines whether the major type of a given {@link CborType} equals the major type of this {@link CborType}.
+ *
+ * @param other the {@link CborType} to compare against, cannot be null
.
+ * @return true
if the given {@link CborType} is of the same major type as this {@link CborType}, false
otherwise.
+ * @throws IllegalArgumentException in case the given argument was null
.
+ */
+ public boolean isEqualType(CborType other) {
+ if (other == null) {
+ throw new IllegalArgumentException("Parameter cannot be null!");
+ }
+ return m_major == other.m_major;
+ }
+
+ /**
+ * Determines whether the major type of a given byte value (representing an encoded {@link CborType}) equals the major type of this {@link CborType}.
+ *
+ * @param encoded the encoded CBOR type to compare.
+ * @return true
if the given byte value represents the same major type as this {@link CborType}, false
otherwise.
+ */
+ public boolean isEqualType(int encoded) {
+ return m_major == ((encoded & 0xff) >>> 5);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getName(m_major)).append('(').append(m_additional).append(')');
+ return sb.toString();
+ }
+}
diff --git a/plugins/com.minres.scviewer.database.ftr/src/jacob/packageinfo b/plugins/com.minres.scviewer.database.ftr/src/jacob/packageinfo
new file mode 100644
index 0000000..a4f1546
--- /dev/null
+++ b/plugins/com.minres.scviewer.database.ftr/src/jacob/packageinfo
@@ -0,0 +1 @@
+version 1.0
\ No newline at end of file
diff --git a/plugins/com.minres.scviewer.database.sqlite/pom.xml b/plugins/com.minres.scviewer.database.sqlite/pom.xml
index 6acc76f..38f7d5c 100644
--- a/plugins/com.minres.scviewer.database.sqlite/pom.xml
+++ b/plugins/com.minres.scviewer.database.sqlite/pom.xml
@@ -4,7 +4,7 @@