/** * Encode a null value. * @param dst The destination to which encoded digits are written. * @param ord The {@link Order} to respect while encoding {@code val}. * @return the number of bytes written. */ public static int encodeNull(PositionedByteRange dst, Order ord) { dst.put(ord.apply(NULL)); return 1; }
/** * Create a terminated version of the {@code wrapped}. * @throws IllegalArgumentException when {@code term} is null or empty. */ public TerminatedWrapper(DataType<T> wrapped, byte[] term) { if (null == term || term.length == 0) { throw new IllegalArgumentException("terminator must be non-null and non-empty."); } this.wrapped = wrapped; wrapped.getOrder().apply(term); this.term = term; }
/** * Decode an {@code int8} value. * @see #encodeInt8(PositionedByteRange, byte, Order) */ public static byte decodeInt8(PositionedByteRange src) { final byte header = src.get(); assert header == FIXED_INT8 || header == DESCENDING.apply(FIXED_INT8); Order ord = header == FIXED_INT8 ? ASCENDING : DESCENDING; return (byte)((ord.apply(src.get()) ^ 0x80) & 0xff); }
@Override public int encode(PositionedByteRange dst, String val) { byte[] s = Bytes.toBytes(val); order.apply(s); dst.put(s); return s.length; } }
/** * Decode an {@code int16} value. * @see #encodeInt16(PositionedByteRange, short, Order) */ public static short decodeInt16(PositionedByteRange src) { final byte header = src.get(); assert header == FIXED_INT16 || header == DESCENDING.apply(FIXED_INT16); Order ord = header == FIXED_INT16 ? ASCENDING : DESCENDING; short val = (short) ((ord.apply(src.get()) ^ 0x80) & 0xff); val = (short) ((val << 8) + (ord.apply(src.get()) & 0xff)); return val; }
/** * Return true when the next encoded value in {@code src} uses Numeric * encoding and is {@code NaN}, false otherwise. */ public static boolean isNumericNaN(PositionedByteRange src) { return NAN == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses fixed-width * Int32 encoding, false otherwise. */ public static boolean isFixedInt32(PositionedByteRange src) { return FIXED_INT32 == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses BlobVar * encoding, false otherwise. */ public static boolean isBlobVar(PositionedByteRange src) { return BLOB_VAR == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses fixed-width * Int64 encoding, false otherwise. */ public static boolean isFixedInt64(PositionedByteRange src) { return FIXED_INT64 == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses Numeric * encoding, false otherwise. {@code NaN}, {@code +/-Inf} are valid Numeric * values. */ public static boolean isNumeric(PositionedByteRange src) { byte x = (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); return x >= NEG_INF && x <= NAN; }
/** * Return true when the next encoded value in {@code src} uses Numeric * encoding and is {@code Infinite}, false otherwise. */ public static boolean isNumericInfinite(PositionedByteRange src) { byte x = (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); return NEG_INF == x || POS_INF == x; }
/** * Return true when the next encoded value in {@code src} uses fixed-width * Int8 encoding, false otherwise. */ public static boolean isFixedInt8(PositionedByteRange src) { return FIXED_INT8 == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses BlobCopy * encoding, false otherwise. */ public static boolean isBlobCopy(PositionedByteRange src) { return BLOB_COPY == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses fixed-width * Int16 encoding, false otherwise. */ public static boolean isFixedInt16(PositionedByteRange src) { return FIXED_INT16 == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses Text encoding, * false otherwise. */ public static boolean isText(PositionedByteRange src) { return TEXT == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} is null, false * otherwise. */ public static boolean isNull(PositionedByteRange src) { return NULL == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses Numeric * encoding and is {@code 0}, false otherwise. */ public static boolean isNumericZero(PositionedByteRange src) { return ZERO == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses fixed-width * Float32 encoding, false otherwise. */ public static boolean isFixedFloat32(PositionedByteRange src) { return FIXED_FLOAT32 == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Return true when the next encoded value in {@code src} uses fixed-width * Float64 encoding, false otherwise. */ public static boolean isFixedFloat64(PositionedByteRange src) { return FIXED_FLOAT64 == (-1 == Integer.signum(src.peek()) ? DESCENDING : ASCENDING).apply(src.peek()); }
/** * Encode an {@code int8} value using the fixed-length encoding. * @return the number of bytes written. * @see #encodeInt64(PositionedByteRange, long, Order) * @see #decodeInt8(PositionedByteRange) */ public static int encodeInt8(PositionedByteRange dst, byte val, Order ord) { final int offset = dst.getOffset(), start = dst.getPosition(); dst.put(FIXED_INT8) .put((byte) (val ^ 0x80)); ord.apply(dst.getBytes(), offset + start, 2); return 2; }