Interface ByteSource
-
- All Known Implementing Classes:
ByteSource.AbstractEscaper
,ByteSource.AccessorEscaper
,ByteSource.ArrayEscaper
,ByteSource.BufferEscaper
,ByteSource.MemoryEscaper
,ByteSource.Multi
,ByteSource.Number
,ByteSource.Peekable
,ByteSource.Separator
,ByteSource.SignedFixedLengthFloat
,ByteSource.SignedFixedLengthNumber
,ByteSource.VariableLengthInteger
,ByteSource.VariableLengthUnsignedInteger
public interface ByteSource
A stream of bytes, used for byte-order-comparable representations of data, and utilities to convert various values to their byte-ordered translation. See ByteComparable.md for details about the encoding scheme.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ByteSource.AbstractEscaper
Variable-length encoding.static class
ByteSource.AccessorEscaper<V>
static class
ByteSource.ArrayEscaper
static class
ByteSource.BufferEscaper
static class
ByteSource.MemoryEscaper
static class
ByteSource.Multi
Combination of multiple byte sources.static class
ByteSource.Number
static class
ByteSource.Peekable
static class
ByteSource.Separator
Construct the shortest common prefix of prevMax and currMin that separates those two byte streams.static class
ByteSource.SignedFixedLengthFloat<V>
Fixed length signed floating point number encoding.static class
ByteSource.SignedFixedLengthNumber<V>
Fixed length signed number encoding.static class
ByteSource.VariableLengthInteger
Variable-length encoding for signed integers.static class
ByteSource.VariableLengthUnsignedInteger
Variable-length encoding for unsigned integers.
-
Field Summary
Fields Modifier and Type Field Description static ByteSource
EMPTY
static int
END_OF_STREAM
Value returned if at the end of the stream.static int
ESCAPE
Escape value.static int
ESCAPED_0_CONT
static int
ESCAPED_0_DONE
static int
EXCLUDED
static int
GT_NEXT_COMPONENT
static int
GTGT_NEXT_COMPONENT
static int
LT_NEXT_COMPONENT
static int
LTLT_NEXT_COMPONENT
static int
MAX_NEXT_COMPONENT
static int
MAX_SEPARATOR
static int
MIN_NEXT_COMPONENT
static int
MIN_SEPARATOR
static int
NEXT_COMPONENT
static int
NEXT_COMPONENT_EMPTY
static int
NEXT_COMPONENT_EMPTY_REVERSED
static int
NEXT_COMPONENT_NULL
static int
TERMINATOR
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static ByteSource
cut(ByteSource src, int cutoff)
static ByteSource
cutOrRightPad(ByteSource src, int cutoff, int padding)
Wrap a ByteSource in a length-fixing facade.static ByteSource
fixedLength(byte[] b)
A byte source of the given bytes without any encoding.static ByteSource
fixedLength(byte[] b, int offset, int length)
static ByteSource
fixedLength(java.nio.ByteBuffer b)
A byte source of the given bytes without any encoding.static <V> ByteSource
fixedLength(ValueAccessor<V> accessor, V data)
A byte source of the given bytes without any encoding.int
next()
Consume the next byte, unsigned.static ByteSource
of(byte[] buf, ByteComparable.Version version)
Encodes a byte array as a byte-comparable source that has 0s escaped and finishes in an escape.static ByteSource
of(int value)
static ByteSource
of(long value)
static ByteSource
of(java.lang.String s, ByteComparable.Version version)
static ByteSource
of(java.nio.ByteBuffer buf, ByteComparable.Version version)
Encodes a byte buffer as a byte-comparable source that has 0s escaped and finishes in an escape.static <V> ByteSource
of(ValueAccessor<V> accessor, V data, ByteComparable.Version version)
Encodes byte-accessible data as a byte-comparable source that has 0s escaped and finishes in an escaped state.static ByteSource
ofMemory(long address, int length, ByteComparable.Version version)
Encodes a memory range as a byte-comparable source that has 0s escaped and finishes in an escape.static ByteSource
oneByte(int i)
static <V> ByteSource
optionalFixedLength(ValueAccessor<V> accessor, V data)
static <V> ByteSource
optionalSignedFixedLengthFloat(ValueAccessor<V> accessor, V data)
Produce a source for a signed fixed-length floating-point number, also translating empty to null.static <V> ByteSource
optionalSignedFixedLengthNumber(ValueAccessor<V> accessor, V data)
Produce a source for a signed fixed-length number, also translating empty to null.static ByteSource.Peekable
peekable(ByteSource p)
static ByteSource
separatorGt(ByteSource prevMax, ByteSource currMin)
Returns a separator for two byte sources, i.e.static ByteSource
separatorPrefix(ByteSource prevMax, ByteSource currMin)
Returns a separator for two byte sources, i.e.static <V> ByteSource
signedFixedLengthFloat(ValueAccessor<V> accessor, V data)
Produce a source for a signed fixed-length floating-point number.static <V> ByteSource
signedFixedLengthNumber(ValueAccessor<V> accessor, V data)
Produce a source for a signed fixed-length number.static ByteSource
variableLengthInteger(long value)
Produce a source for a signed integer, stored using variable length encoding.static ByteSource
withTerminator(int terminator, ByteSource... srcs)
Combines a chain of sources, turning their weak-prefix-free byte-comparable representation into the combination's prefix-free byte-comparable representation, with the included terminator character.static ByteSource
withTerminatorLegacy(int terminator, ByteSource... srcs)
As above, but permits any separator.static ByteSource
withTerminatorMaybeLegacy(ByteComparable.Version version, int legacyTerminator, ByteSource... srcs)
-
-
-
Field Detail
-
END_OF_STREAM
static final int END_OF_STREAM
Value returned if at the end of the stream.- See Also:
- Constant Field Values
-
EMPTY
static final ByteSource EMPTY
-
ESCAPE
static final int ESCAPE
Escape value. Used, among other things, to mark the end of subcomponents (so that shorter compares before anything longer). Actual zeros in input need to be escaped if this is in use (seeByteSource.AbstractEscaper
).- See Also:
- Constant Field Values
-
ESCAPED_0_CONT
static final int ESCAPED_0_CONT
- See Also:
- Constant Field Values
-
ESCAPED_0_DONE
static final int ESCAPED_0_DONE
- See Also:
- Constant Field Values
-
MIN_SEPARATOR
static final int MIN_SEPARATOR
- See Also:
- Constant Field Values
-
MAX_SEPARATOR
static final int MAX_SEPARATOR
- See Also:
- Constant Field Values
-
NEXT_COMPONENT
static final int NEXT_COMPONENT
- See Also:
- Constant Field Values
-
NEXT_COMPONENT_EMPTY
static final int NEXT_COMPONENT_EMPTY
- See Also:
- Constant Field Values
-
NEXT_COMPONENT_EMPTY_REVERSED
static final int NEXT_COMPONENT_EMPTY_REVERSED
- See Also:
- Constant Field Values
-
NEXT_COMPONENT_NULL
static final int NEXT_COMPONENT_NULL
- See Also:
- Constant Field Values
-
MIN_NEXT_COMPONENT
static final int MIN_NEXT_COMPONENT
- See Also:
- Constant Field Values
-
MAX_NEXT_COMPONENT
static final int MAX_NEXT_COMPONENT
- See Also:
- Constant Field Values
-
TERMINATOR
static final int TERMINATOR
- See Also:
- Constant Field Values
-
LT_NEXT_COMPONENT
static final int LT_NEXT_COMPONENT
- See Also:
- Constant Field Values
-
GT_NEXT_COMPONENT
static final int GT_NEXT_COMPONENT
- See Also:
- Constant Field Values
-
LTLT_NEXT_COMPONENT
static final int LTLT_NEXT_COMPONENT
- See Also:
- Constant Field Values
-
GTGT_NEXT_COMPONENT
static final int GTGT_NEXT_COMPONENT
- See Also:
- Constant Field Values
-
EXCLUDED
static final int EXCLUDED
- See Also:
- Constant Field Values
-
-
Method Detail
-
next
int next()
Consume the next byte, unsigned. Must be between 0 and 255, or END_OF_STREAM if there are no more bytes.
-
of
static <V> ByteSource of(ValueAccessor<V> accessor, V data, ByteComparable.Version version)
Encodes byte-accessible data as a byte-comparable source that has 0s escaped and finishes in an escaped state. This provides a weakly-prefix-free byte-comparable version of the content to use in sequences. (SeeByteSource.AbstractEscaper
for a detailed explanation.)
-
of
static ByteSource of(java.nio.ByteBuffer buf, ByteComparable.Version version)
Encodes a byte buffer as a byte-comparable source that has 0s escaped and finishes in an escape. This provides a weakly-prefix-free byte-comparable version of the content to use in sequences. (See ByteSource.BufferEscaper/Multi for explanation.)
-
of
static ByteSource of(byte[] buf, ByteComparable.Version version)
Encodes a byte array as a byte-comparable source that has 0s escaped and finishes in an escape. This provides a prefix-free byte-comparable version of the content to use in sequences. (See ByteSource.BufferEscaper/Multi for explanation.)
-
ofMemory
static ByteSource ofMemory(long address, int length, ByteComparable.Version version)
Encodes a memory range as a byte-comparable source that has 0s escaped and finishes in an escape. This provides a weakly-prefix-free byte-comparable version of the content to use in sequences. (See ByteSource.BufferEscaper/Multi for explanation.)
-
withTerminator
static ByteSource withTerminator(int terminator, ByteSource... srcs)
Combines a chain of sources, turning their weak-prefix-free byte-comparable representation into the combination's prefix-free byte-comparable representation, with the included terminator character. For correctness, the terminator must be within MIN-MAX_SEPARATOR and outside the range reserved for NEXT_COMPONENT markers. Typically TERMINATOR, or LT/GT_NEXT_COMPONENT if used for partially specified bounds.
-
withTerminatorLegacy
static ByteSource withTerminatorLegacy(int terminator, ByteSource... srcs)
As above, but permits any separator. The legacy format wasn't using weak prefix freedom and has some non-reversible transformations.
-
withTerminatorMaybeLegacy
static ByteSource withTerminatorMaybeLegacy(ByteComparable.Version version, int legacyTerminator, ByteSource... srcs)
-
of
static ByteSource of(java.lang.String s, ByteComparable.Version version)
-
of
static ByteSource of(long value)
-
of
static ByteSource of(int value)
-
optionalSignedFixedLengthNumber
static <V> ByteSource optionalSignedFixedLengthNumber(ValueAccessor<V> accessor, V data)
Produce a source for a signed fixed-length number, also translating empty to null. The first byte has its sign bit inverted, and the rest are passed unchanged. Presumes that the length of the buffer is always either 0 or constant for the type, which permits decoding and ensures the representation is prefix-free.
-
signedFixedLengthNumber
static <V> ByteSource signedFixedLengthNumber(ValueAccessor<V> accessor, V data)
Produce a source for a signed fixed-length number. The first byte has its sign bit inverted, and the rest are passed unchanged. Presumes that the length of the buffer is always constant for the type.
-
optionalSignedFixedLengthFloat
static <V> ByteSource optionalSignedFixedLengthFloat(ValueAccessor<V> accessor, V data)
Produce a source for a signed fixed-length floating-point number, also translating empty to null. If sign bit is on, returns negated bytes. If not, add the sign bit value. (Sign of IEEE floats is the highest bit, the rest can be compared in magnitude by byte comparison.) Presumes that the length of the buffer is always either 0 or constant for the type, which permits decoding and ensures the representation is prefix-free.
-
signedFixedLengthFloat
static <V> ByteSource signedFixedLengthFloat(ValueAccessor<V> accessor, V data)
Produce a source for a signed fixed-length floating-point number. If sign bit is on, returns negated bytes. If not, add the sign bit value. (Sign of IEEE floats is the highest bit, the rest can be compared in magnitude by byte comparison.) Presumes that the length of the buffer is always constant for the type.
-
variableLengthInteger
static ByteSource variableLengthInteger(long value)
Produce a source for a signed integer, stored using variable length encoding. The representation uses between 1 and 9 bytes, is prefix-free and compares correctly.
-
separatorPrefix
static ByteSource separatorPrefix(ByteSource prevMax, ByteSource currMin)
Returns a separator for two byte sources, i.e. something that is definitely > prevMax, and <= currMin, assuming prevMax < currMin. This returns the shortest prefix of currMin that is greater than prevMax.
-
separatorGt
static ByteSource separatorGt(ByteSource prevMax, ByteSource currMin)
Returns a separator for two byte sources, i.e. something that is definitely > prevMax, and <= currMin, assuming prevMax < currMin. This is a source of length 1 longer than the common prefix of the two sources, with last byte one higher than the prevMax source.
-
oneByte
static ByteSource oneByte(int i)
-
cut
static ByteSource cut(ByteSource src, int cutoff)
-
cutOrRightPad
static ByteSource cutOrRightPad(ByteSource src, int cutoff, int padding)
Wrap a ByteSource in a length-fixing facade. If the length ofsrc
is less thancutoff
, then pad it on the right withpadding
until the overall length equalscutoff
. If the length ofsrc
is greater thancutoff
, then truncatesrc
to that size. Effectively a noop ifsrc
happens to have lengthcutoff
.- Parameters:
src
- the input source to wrapcutoff
- the size of the source returnedpadding
- a padding byte (an int subject to a 0xFF mask)
-
optionalFixedLength
static <V> ByteSource optionalFixedLength(ValueAccessor<V> accessor, V data)
-
fixedLength
static <V> ByteSource fixedLength(ValueAccessor<V> accessor, V data)
A byte source of the given bytes without any encoding. The resulting source is only guaranteed to give correct comparison results and be prefix-free if the underlying type has a fixed length. In tests, this method is also used to generate non-escaped test cases.
-
fixedLength
static ByteSource fixedLength(java.nio.ByteBuffer b)
A byte source of the given bytes without any encoding. The resulting source is only guaranteed to give correct comparison results and be prefix-free if the underlying type has a fixed length. In tests, this method is also used to generate non-escaped test cases.
-
fixedLength
static ByteSource fixedLength(byte[] b)
A byte source of the given bytes without any encoding. If used in a sequence, the resulting source is only guaranteed to give correct comparison results if the underlying type has a fixed length. In tests, this method is also used to generate non-escaped test cases.
-
fixedLength
static ByteSource fixedLength(byte[] b, int offset, int length)
-
peekable
static ByteSource.Peekable peekable(ByteSource p)
-
-