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 ClassesModifier and TypeInterfaceDescriptionstatic classVariable-length encoding.static classstatic classstatic classstatic classstatic classCombination of multiple byte sources.static classstatic classstatic classConstruct the shortest common prefix of prevMax and currMin that separates those two byte streams.static classFixed length signed floating point number encoding.static classFixed length signed number encoding.static classVariable-length encoding for signed integers.static classVariable-length encoding for unsigned integers. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ByteSourcestatic final intValue returned if at the end of the stream.static final intEscape value.static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 ByteSourceA 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(String s, ByteComparable.Version version) static ByteSourceof(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.Peekablestatic 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 Details
-
END_OF_STREAM
static final int END_OF_STREAMValue returned if at the end of the stream.- See Also:
-
EMPTY
-
ESCAPE
static final int ESCAPEEscape 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:
-
ESCAPED_0_CONT
static final int ESCAPED_0_CONT- See Also:
-
ESCAPED_0_DONE
static final int ESCAPED_0_DONE- See Also:
-
MIN_SEPARATOR
static final int MIN_SEPARATOR- See Also:
-
MAX_SEPARATOR
static final int MAX_SEPARATOR- See Also:
-
NEXT_COMPONENT
static final int NEXT_COMPONENT- See Also:
-
NEXT_COMPONENT_EMPTY
static final int NEXT_COMPONENT_EMPTY- See Also:
-
NEXT_COMPONENT_EMPTY_REVERSED
static final int NEXT_COMPONENT_EMPTY_REVERSED- See Also:
-
NEXT_COMPONENT_NULL
static final int NEXT_COMPONENT_NULL- See Also:
-
MIN_NEXT_COMPONENT
static final int MIN_NEXT_COMPONENT- See Also:
-
MAX_NEXT_COMPONENT
static final int MAX_NEXT_COMPONENT- See Also:
-
TERMINATOR
static final int TERMINATOR- See Also:
-
LT_NEXT_COMPONENT
static final int LT_NEXT_COMPONENT- See Also:
-
GT_NEXT_COMPONENT
static final int GT_NEXT_COMPONENT- See Also:
-
LTLT_NEXT_COMPONENT
static final int LTLT_NEXT_COMPONENT- See Also:
-
GTGT_NEXT_COMPONENT
static final int GTGT_NEXT_COMPONENT- See Also:
-
EXCLUDED
static final int EXCLUDED- See Also:
-
-
Method Details
-
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
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
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
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
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
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
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
-
of
-
of
-
optionalSignedFixedLengthNumber
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
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
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
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
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
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
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
-
cut
-
cutOrRightPad
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
-
fixedLength
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
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
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
-
peekable
-