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 ByteSourceA 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 classByteSource.AbstractEscaperVariable-length encoding.static classByteSource.AccessorEscaper<V>static classByteSource.ArrayEscaperstatic classByteSource.BufferEscaperstatic classByteSource.MemoryEscaperstatic classByteSource.MultiCombination of multiple byte sources.static classByteSource.Numberstatic classByteSource.Peekablestatic classByteSource.SeparatorConstruct the shortest common prefix of prevMax and currMin that separates those two byte streams.static classByteSource.SignedFixedLengthFloat<V>Fixed length signed floating point number encoding.static classByteSource.SignedFixedLengthNumber<V>Fixed length signed number encoding.static classByteSource.VariableLengthIntegerVariable-length encoding for signed integers.static classByteSource.VariableLengthUnsignedIntegerVariable-length encoding for unsigned integers.
-
Field Summary
Fields Modifier and Type Field Description static ByteSourceEMPTYstatic intEND_OF_STREAMValue returned if at the end of the stream.static intESCAPEEscape value.static intESCAPED_0_CONTstatic intESCAPED_0_DONEstatic intEXCLUDEDstatic intGT_NEXT_COMPONENTstatic intGTGT_NEXT_COMPONENTstatic intLT_NEXT_COMPONENTstatic intLTLT_NEXT_COMPONENTstatic intMAX_NEXT_COMPONENTstatic intMAX_SEPARATORstatic intMIN_NEXT_COMPONENTstatic intMIN_SEPARATORstatic intNEXT_COMPONENTstatic intNEXT_COMPONENT_EMPTYstatic intNEXT_COMPONENT_EMPTY_REVERSEDstatic intNEXT_COMPONENT_NULLstatic intTERMINATOR
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static ByteSourcecut(ByteSource src, int cutoff)static ByteSourcecutOrRightPad(ByteSource src, int cutoff, int padding)Wrap a ByteSource in a length-fixing facade.static ByteSourcefixedLength(byte[] b)A byte source of the given bytes without any encoding.static ByteSourcefixedLength(byte[] b, int offset, int length)static ByteSourcefixedLength(java.nio.ByteBuffer b)A byte source of the given bytes without any encoding.static <V> ByteSourcefixedLength(ValueAccessor<V> accessor, V data)A byte source of the given bytes without any encoding.intnext()Consume the next byte, unsigned.static ByteSourceof(byte[] buf, ByteComparable.Version version)Encodes a byte array as a byte-comparable source that has 0s escaped and finishes in an escape.static ByteSourceof(int value)static ByteSourceof(long value)static ByteSourceof(java.lang.String s, ByteComparable.Version version)static ByteSourceof(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> ByteSourceof(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 ByteSourceofMemory(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 ByteSourceoneByte(int i)static <V> ByteSourceoptionalFixedLength(ValueAccessor<V> accessor, V data)static <V> ByteSourceoptionalSignedFixedLengthFloat(ValueAccessor<V> accessor, V data)Produce a source for a signed fixed-length floating-point number, also translating empty to null.static <V> ByteSourceoptionalSignedFixedLengthNumber(ValueAccessor<V> accessor, V data)Produce a source for a signed fixed-length number, also translating empty to null.static ByteSource.Peekablepeekable(ByteSource p)static ByteSourceseparatorGt(ByteSource prevMax, ByteSource currMin)Returns a separator for two byte sources, i.e.static ByteSourceseparatorPrefix(ByteSource prevMax, ByteSource currMin)Returns a separator for two byte sources, i.e.static <V> ByteSourcesignedFixedLengthFloat(ValueAccessor<V> accessor, V data)Produce a source for a signed fixed-length floating-point number.static <V> ByteSourcesignedFixedLengthNumber(ValueAccessor<V> accessor, V data)Produce a source for a signed fixed-length number.static ByteSourcevariableLengthInteger(long value)Produce a source for a signed integer, stored using variable length encoding.static ByteSourcewithTerminator(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 ByteSourcewithTerminatorLegacy(int terminator, ByteSource... srcs)As above, but permits any separator.static ByteSourcewithTerminatorMaybeLegacy(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.AbstractEscaperfor 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 ofsrcis less thancutoff, then pad it on the right withpaddinguntil the overall length equalscutoff. If the length ofsrcis greater thancutoff, then truncatesrcto that size. Effectively a noop ifsrchappens 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)
-
-