@Test public void testSkip() { BigDecimal longMax = BigDecimal.valueOf(Long.MAX_VALUE); double negInf = Double.NEGATIVE_INFINITY; BigDecimal negLarge = longMax.multiply(longMax).negate(); BigDecimal negMed = new BigDecimal("-10.0"); BigDecimal negSmall = new BigDecimal("-0.0010"); long zero = 0l; BigDecimal posSmall = negSmall.negate(); BigDecimal posMed = negMed.negate(); BigDecimal posLarge = negLarge.negate(); double posInf = Double.POSITIVE_INFINITY; double nan = Double.NaN; byte int8 = 100; short int16 = 100; int int32 = 100; long int64 = 100l; float float32 = 100.0f; double float64 = 100.0d; String text = "hello world."; byte[] blobVar = Bytes.toBytes("foo"); byte[] blobCopy = Bytes.toBytes("bar"); for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) { PositionedByteRange buff = new SimplePositionedByteRange(30); int o; o = OrderedBytes.encodeNull(buff, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, negInf, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, negLarge, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, negMed, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, negSmall, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, zero, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, posSmall, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, posMed, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, posLarge, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, posInf, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeNumeric(buff, nan, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeInt8(buff, int8, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeInt16(buff, int16, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeInt32(buff, int32, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeInt64(buff, int64, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeFloat32(buff, float32, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeFloat64(buff, float64, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeString(buff, text, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.setPosition(0); o = OrderedBytes.encodeBlobVar(buff, blobVar, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); buff.set(blobCopy.length + (Order.ASCENDING == ord ? 1 : 2)); o = OrderedBytes.encodeBlobCopy(buff, blobCopy, ord); buff.setPosition(0); assertEquals(o, OrderedBytes.skip(buff)); } }
public static int skip(PositionedByteRange src) { final int start = src.getPosition(); byte header = src.get(); Order ord = (-1 == Integer.signum(header)) ? DESCENDING : ASCENDING; header = ord.apply(header); switch (header) { case NULL: case NEG_INF: return 1; case NEG_LARGE: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_MED_MIN: case NEG_MED_MIN + 0x01: case NEG_MED_MIN + 0x02: case NEG_MED_MIN + 0x03: case NEG_MED_MIN + 0x04: case NEG_MED_MIN + 0x05: case NEG_MED_MIN + 0x06: case NEG_MED_MIN + 0x07: case NEG_MED_MIN + 0x08: case NEG_MED_MIN + 0x09: case NEG_MED_MAX: skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_SMALL: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case ZERO: return 1; case POS_SMALL: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_MED_MIN: case POS_MED_MIN + 0x01: case POS_MED_MIN + 0x02: case POS_MED_MIN + 0x03: case POS_MED_MIN + 0x04: case POS_MED_MIN + 0x05: case POS_MED_MIN + 0x06: case POS_MED_MIN + 0x07: case POS_MED_MIN + 0x08: case POS_MED_MIN + 0x09: case POS_MED_MAX: skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_LARGE: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_INF: return 1; case NAN: return 1; case FIXED_INT8: src.setPosition(src.getPosition() + 1); return src.getPosition() - start; case FIXED_INT16: src.setPosition(src.getPosition() + 2); return src.getPosition() - start; case FIXED_INT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_INT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case FIXED_FLOAT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_FLOAT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case TEXT: do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; case BLOB_VAR: do { header = ord.apply(src.get()); } while ((byte) (header & 0x80) != TERM); return src.getPosition() - start; case BLOB_COPY: if (Order.DESCENDING == ord) { do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; } else { src.setPosition(src.getLength()); return src.getPosition() - start; } default: throw unexpectedHeader(header); } }
OrderedBytes { public static int skip(PositionedByteRange src) { final int start = src.getPosition(); byte header = src.get(); Order ord = (-1 == Integer.signum(header)) ? DESCENDING : ASCENDING; header = ord.apply(header); switch (header) { case NULL: case NEG_INF: return 1; case NEG_LARGE: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_MED_MIN: case NEG_MED_MIN + 0x01: case NEG_MED_MIN + 0x02: case NEG_MED_MIN + 0x03: case NEG_MED_MIN + 0x04: case NEG_MED_MIN + 0x05: case NEG_MED_MIN + 0x06: case NEG_MED_MIN + 0x07: case NEG_MED_MIN + 0x08: case NEG_MED_MIN + 0x09: case NEG_MED_MAX: skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_SMALL: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case ZERO: return 1; case POS_SMALL: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_MED_MIN: case POS_MED_MIN + 0x01: case POS_MED_MIN + 0x02: case POS_MED_MIN + 0x03: case POS_MED_MIN + 0x04: case POS_MED_MIN + 0x05: case POS_MED_MIN + 0x06: case POS_MED_MIN + 0x07: case POS_MED_MIN + 0x08: case POS_MED_MIN + 0x09: case POS_MED_MAX: skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_LARGE: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_INF: return 1; case NAN: return 1; case FIXED_INT8: src.setPosition(src.getPosition() + 1); return src.getPosition() - start; case FIXED_INT16: src.setPosition(src.getPosition() + 2); return src.getPosition() - start; case FIXED_INT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_INT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case FIXED_FLOAT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_FLOAT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case TEXT: do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; case BLOB_VAR: do { header = ord.apply(src.get()); } while ((byte) (header & 0x80) != TERM); return src.getPosition() - start; case BLOB_COPY: if (Order.DESCENDING == ord) { do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; } else { src.setPosition(src.getLength()); return src.getPosition() - start; } default: throw unexpectedHeader(header); } } }
OrderedBytes { public static int skip(PositionedByteRange src) { final int start = src.getPosition(); byte header = src.get(); Order ord = (-1 == Integer.signum(header)) ? DESCENDING : ASCENDING; header = ord.apply(header); switch (header) { case NULL: case NEG_INF: return 1; case NEG_LARGE: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_MED_MIN: case NEG_MED_MIN + 0x01: case NEG_MED_MIN + 0x02: case NEG_MED_MIN + 0x03: case NEG_MED_MIN + 0x04: case NEG_MED_MIN + 0x05: case NEG_MED_MIN + 0x06: case NEG_MED_MIN + 0x07: case NEG_MED_MIN + 0x08: case NEG_MED_MIN + 0x09: case NEG_MED_MAX: skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_SMALL: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case ZERO: return 1; case POS_SMALL: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_MED_MIN: case POS_MED_MIN + 0x01: case POS_MED_MIN + 0x02: case POS_MED_MIN + 0x03: case POS_MED_MIN + 0x04: case POS_MED_MIN + 0x05: case POS_MED_MIN + 0x06: case POS_MED_MIN + 0x07: case POS_MED_MIN + 0x08: case POS_MED_MIN + 0x09: case POS_MED_MAX: skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_LARGE: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_INF: return 1; case NAN: return 1; case FIXED_INT8: src.setPosition(src.getPosition() + 1); return src.getPosition() - start; case FIXED_INT16: src.setPosition(src.getPosition() + 2); return src.getPosition() - start; case FIXED_INT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_INT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case FIXED_FLOAT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_FLOAT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case TEXT: do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; case BLOB_VAR: do { header = ord.apply(src.get()); } while ((byte) (header & 0x80) != TERM); return src.getPosition() - start; case BLOB_COPY: if (Order.DESCENDING == ord) { do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; } else { src.setPosition(src.getLength()); return src.getPosition() - start; } default: throw unexpectedHeader(header); } }  }
OrderedBytes { public static int skip(PositionedByteRange src) { final int start = src.getPosition(); byte header = src.get(); Order ord = (-1 == Integer.signum(header)) ? DESCENDING : ASCENDING; header = ord.apply(header); switch (header) { case NULL: case NEG_INF: return 1; case NEG_LARGE: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_MED_MIN: case NEG_MED_MIN + 0x01: case NEG_MED_MIN + 0x02: case NEG_MED_MIN + 0x03: case NEG_MED_MIN + 0x04: case NEG_MED_MIN + 0x05: case NEG_MED_MIN + 0x06: case NEG_MED_MIN + 0x07: case NEG_MED_MIN + 0x08: case NEG_MED_MIN + 0x09: case NEG_MED_MAX: skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_SMALL: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case ZERO: return 1; case POS_SMALL: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_MED_MIN: case POS_MED_MIN + 0x01: case POS_MED_MIN + 0x02: case POS_MED_MIN + 0x03: case POS_MED_MIN + 0x04: case POS_MED_MIN + 0x05: case POS_MED_MIN + 0x06: case POS_MED_MIN + 0x07: case POS_MED_MIN + 0x08: case POS_MED_MIN + 0x09: case POS_MED_MAX: skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_LARGE: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_INF: return 1; case NAN: return 1; case FIXED_INT8: src.setPosition(src.getPosition() + 1); return src.getPosition() - start; case FIXED_INT16: src.setPosition(src.getPosition() + 2); return src.getPosition() - start; case FIXED_INT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_INT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case FIXED_FLOAT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_FLOAT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case TEXT: do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; case BLOB_VAR: do { header = ord.apply(src.get()); } while ((byte) (header & 0x80) != TERM); return src.getPosition() - start; case BLOB_COPY: if (Order.DESCENDING == ord) { do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; } else { src.setPosition(src.getLength()); return src.getPosition() - start; } default: throw unexpectedHeader(header); } }  static int encodeNumeric(PositionedByteRange dst, long val, Order ord); static int encodeNumeric(PositionedByteRange dst, double val, Order ord); static int encodeNumeric(PositionedByteRange dst, BigDecimal val, Order ord); static double decodeNumericAsDouble(PositionedByteRange src); static long decodeNumericAsLong(PositionedByteRange src); static BigDecimal decodeNumericAsBigDecimal(PositionedByteRange src); static int encodeString(PositionedByteRange dst, String val, Order ord); static String decodeString(PositionedByteRange src); static int blobVarEncodedLength(int len); static int encodeBlobVar(PositionedByteRange dst, byte[] val, int voff, int vlen,
      Order ord); static int encodeBlobVar(PositionedByteRange dst, byte[] val, Order ord); static byte[] decodeBlobVar(PositionedByteRange src); static int encodeBlobCopy(PositionedByteRange dst, byte[] val, int voff, int vlen,
      Order ord); static int encodeBlobCopy(PositionedByteRange dst, byte[] val, Order ord); static byte[] decodeBlobCopy(PositionedByteRange src); static int encodeNull(PositionedByteRange dst, Order ord); static int encodeInt8(PositionedByteRange dst, byte val, Order ord); static byte decodeInt8(PositionedByteRange src); static int encodeInt16(PositionedByteRange dst, short val, Order ord); static short decodeInt16(PositionedByteRange src); static int encodeInt32(PositionedByteRange dst, int val, Order ord); static int decodeInt32(PositionedByteRange src); static int encodeInt64(PositionedByteRange dst, long val, Order ord); static long decodeInt64(PositionedByteRange src); static int encodeFloat32(PositionedByteRange dst, float val, Order ord); static float decodeFloat32(PositionedByteRange src); static int encodeFloat64(PositionedByteRange dst, double val, Order ord); static double decodeFloat64(PositionedByteRange src); static boolean isEncodedValue(PositionedByteRange src); static boolean isNull(PositionedByteRange src); static boolean isNumeric(PositionedByteRange src); static boolean isNumericInfinite(PositionedByteRange src); static boolean isNumericNaN(PositionedByteRange src); static boolean isNumericZero(PositionedByteRange src); static boolean isFixedInt32(PositionedByteRange src); static boolean isFixedInt64(PositionedByteRange src); static boolean isFixedFloat32(PositionedByteRange src); static boolean isFixedFloat64(PositionedByteRange src); static boolean isText(PositionedByteRange src); static boolean isBlobVar(PositionedByteRange src); static boolean isBlobCopy(PositionedByteRange src); static int skip(PositionedByteRange src); static int length(PositionedByteRange buff); }
OrderedBytes { public static int skip(PositionedByteRange src) { final int start = src.getPosition(); byte header = src.get(); Order ord = (-1 == Integer.signum(header)) ? DESCENDING : ASCENDING; header = ord.apply(header); switch (header) { case NULL: case NEG_INF: return 1; case NEG_LARGE: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_MED_MIN: case NEG_MED_MIN + 0x01: case NEG_MED_MIN + 0x02: case NEG_MED_MIN + 0x03: case NEG_MED_MIN + 0x04: case NEG_MED_MIN + 0x05: case NEG_MED_MIN + 0x06: case NEG_MED_MIN + 0x07: case NEG_MED_MIN + 0x08: case NEG_MED_MIN + 0x09: case NEG_MED_MAX: skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case NEG_SMALL: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING != ord); return src.getPosition() - start; case ZERO: return 1; case POS_SMALL: skipVaruint64(src, DESCENDING != ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_MED_MIN: case POS_MED_MIN + 0x01: case POS_MED_MIN + 0x02: case POS_MED_MIN + 0x03: case POS_MED_MIN + 0x04: case POS_MED_MIN + 0x05: case POS_MED_MIN + 0x06: case POS_MED_MIN + 0x07: case POS_MED_MIN + 0x08: case POS_MED_MIN + 0x09: case POS_MED_MAX: skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_LARGE: skipVaruint64(src, DESCENDING == ord); skipSignificand(src, DESCENDING == ord); return src.getPosition() - start; case POS_INF: return 1; case NAN: return 1; case FIXED_INT8: src.setPosition(src.getPosition() + 1); return src.getPosition() - start; case FIXED_INT16: src.setPosition(src.getPosition() + 2); return src.getPosition() - start; case FIXED_INT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_INT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case FIXED_FLOAT32: src.setPosition(src.getPosition() + 4); return src.getPosition() - start; case FIXED_FLOAT64: src.setPosition(src.getPosition() + 8); return src.getPosition() - start; case TEXT: do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; case BLOB_VAR: do { header = ord.apply(src.get()); } while ((byte) (header & 0x80) != TERM); return src.getPosition() - start; case BLOB_COPY: if (Order.DESCENDING == ord) { do { header = ord.apply(src.get()); } while (header != TERM); return src.getPosition() - start; } else { src.setPosition(src.getLength()); return src.getPosition() - start; } default: throw unexpectedHeader(header); } }  static int encodeNumeric(PositionedByteRange dst, long val, Order ord); static int encodeNumeric(PositionedByteRange dst, double val, Order ord); static int encodeNumeric(PositionedByteRange dst, BigDecimal val, Order ord); static double decodeNumericAsDouble(PositionedByteRange src); static long decodeNumericAsLong(PositionedByteRange src); static BigDecimal decodeNumericAsBigDecimal(PositionedByteRange src); static int encodeString(PositionedByteRange dst, String val, Order ord); static String decodeString(PositionedByteRange src); static int blobVarEncodedLength(int len); static int encodeBlobVar(PositionedByteRange dst, byte[] val, int voff, int vlen,
      Order ord); static int encodeBlobVar(PositionedByteRange dst, byte[] val, Order ord); static byte[] decodeBlobVar(PositionedByteRange src); static int encodeBlobCopy(PositionedByteRange dst, byte[] val, int voff, int vlen,
      Order ord); static int encodeBlobCopy(PositionedByteRange dst, byte[] val, Order ord); static byte[] decodeBlobCopy(PositionedByteRange src); static int encodeNull(PositionedByteRange dst, Order ord); static int encodeInt8(PositionedByteRange dst, byte val, Order ord); static byte decodeInt8(PositionedByteRange src); static int encodeInt16(PositionedByteRange dst, short val, Order ord); static short decodeInt16(PositionedByteRange src); static int encodeInt32(PositionedByteRange dst, int val, Order ord); static int decodeInt32(PositionedByteRange src); static int encodeInt64(PositionedByteRange dst, long val, Order ord); static long decodeInt64(PositionedByteRange src); static int encodeFloat32(PositionedByteRange dst, float val, Order ord); static float decodeFloat32(PositionedByteRange src); static int encodeFloat64(PositionedByteRange dst, double val, Order ord); static double decodeFloat64(PositionedByteRange src); static boolean isEncodedValue(PositionedByteRange src); static boolean isNull(PositionedByteRange src); static boolean isNumeric(PositionedByteRange src); static boolean isNumericInfinite(PositionedByteRange src); static boolean isNumericNaN(PositionedByteRange src); static boolean isNumericZero(PositionedByteRange src); static boolean isFixedInt32(PositionedByteRange src); static boolean isFixedInt64(PositionedByteRange src); static boolean isFixedFloat32(PositionedByteRange src); static boolean isFixedFloat64(PositionedByteRange src); static boolean isText(PositionedByteRange src); static boolean isBlobVar(PositionedByteRange src); static boolean isBlobCopy(PositionedByteRange src); static int skip(PositionedByteRange src); static int length(PositionedByteRange buff); static final Charset UTF8; static final int MAX_PRECISION; static final MathContext DEFAULT_MATH_CONTEXT; }