public class BinaryWire extends AbstractWire implements Wire
| Modifier and Type | Class and Description |
|---|---|
protected class |
BinaryWire.BinaryValueIn
Represents a binary input value and provides methods to read and manage the state
of this binary input.
|
protected class |
BinaryWire.BinaryValueOut
Extends the FixedBinaryValueOut class to support binary value outputs with additional logic for converting
and writing different types of numbers, namely integers and longs.
|
protected class |
BinaryWire.FixedBinaryValueOut
Implementation of the ValueOut interface, providing methods to write values in a fixed binary format.
|
WireIn.HeaderTypeWireOut.EndOfWire| Modifier and Type | Field and Description |
|---|---|
protected @NotNull BinaryWire.BinaryValueIn |
valueIn |
bytes, classLookup, commentListener, DEFAULT_USE_PADDING, parent, use8bitMARSHALLABLE_IN_INTERN_SIZE| Constructor and Description |
|---|
BinaryWire()
Constructs a
BinaryWire with default settings and elastic on-heap bytes. |
BinaryWire(@NotNull net.openhft.chronicle.bytes.Bytes<?> bytes)
Constructs a
BinaryWire with default settings. |
BinaryWire(@NotNull net.openhft.chronicle.bytes.Bytes<?> bytes,
boolean fixed,
boolean numericFields,
boolean fieldLess,
int compressedSize,
String compression)
Constructs a BinaryWire with specified configurations.
|
BinaryWire(@NotNull net.openhft.chronicle.bytes.Bytes<?> bytes,
boolean fixed,
boolean numericFields,
boolean fieldLess,
int compressedSize,
String compression,
boolean supportDelta)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
protected @NotNull StringBuilder |
acquireStringBuilder()
Acquires and clears the internal StringBuilder for use.
|
DocumentContext |
acquireWritingDocument(boolean metaData)
Acquire an existing document context for writing if one is open.
|
@NotNull WireOut |
addPadding(int paddingToAdd)
Adds padding to the wire.
|
protected void |
anchor(@NotNull WireOut wire)
Anchor support is not implemented for binary wires.
|
static @NotNull BinaryWire |
binaryOnly(@NotNull net.openhft.chronicle.bytes.Bytes<?> bytes)
Creates and returns a new instance of BinaryWire with the delta support disabled.
|
void |
clear()
|
void |
consumePadding()
Consumes and discards any padding that may exist between the current read position and the next piece of meaningful data.
|
void |
copyOne(@NotNull WireOut wire)
Copies one unit of data from this BinaryWire to the provided WireOut instance.
|
void |
copyTo(@NotNull WireOut wire)
Efficiently copies the remaining content.
|
protected void |
fieldAnchor(@NotNull WireOut wire)
Placeholder or handler for field anchor processing in the WireOut stream.
|
boolean |
fieldLess()
Checks and returns if this BinaryWire instance is field-less.
|
protected @NotNull BinaryWire.FixedBinaryValueOut |
getFixedBinaryValueOut(boolean fixed)
Factory hook for subclasses.
|
Boolean |
getOverrideSelfDescribing()
Returns the override flag controlling whether objects are written in
self-describing form.
|
@NotNull ValueIn |
getValueIn()
Obtains the value associated with a field or event for more advanced use cases.
|
@NotNull ValueOut |
getValueOut()
Retrieves the interface for defining the output of a value
that will be written to the stream.
|
boolean |
isBinary()
Determine whether direct access to the underlying byte() makes sense or should it be treated as text
|
@NotNull net.openhft.chronicle.core.values.BooleanValue |
newBooleanReference()
Creates and returns a new
BooleanValue. |
@NotNull net.openhft.chronicle.core.values.IntArrayValues |
newIntArrayReference()
Creates and returns a new
IntArrayValues. |
@NotNull net.openhft.chronicle.core.values.IntValue |
newIntReference()
Creates and returns a new
IntValue. |
@NotNull net.openhft.chronicle.bytes.ref.BinaryLongArrayReference |
newLongArrayReference()
Creates and returns a new
LongArrayValues. |
@NotNull net.openhft.chronicle.core.values.LongValue |
newLongReference()
Creates and returns a new
LongValue. |
@NotNull net.openhft.chronicle.core.values.TwoLongValue |
newTwoLongReference()
Creates and returns a new
TwoLongValue. |
protected int |
peekCode()
Peeks the code from the current position without advancing the read pointer.
|
@NotNull ValueIn |
read()
Read the next value when field ordering is not known.
|
@NotNull ValueIn |
read(@NotNull String fieldName)
Look up a field by name.
|
@NotNull ValueIn |
read(@NotNull StringBuilder name)
Reads the next field identifier into
name. |
@NotNull ValueIn |
read(@NotNull WireKey key)
Look up a value using a
WireKey. |
protected <T> ValueIn |
read2(CharSequence keyName,
int keyCode,
T defaultSource,
@NotNull Function<T,Object> defaultLookup,
@NotNull net.openhft.chronicle.wire.ValueInState curr,
@NotNull StringBuilder sb,
CharSequence name)
A secondary method to continue the field search process, specifically to handle cases where the field may
have been missed in a previous pass or if the field still hasn't been found.
|
@NotNull Wire |
readComment(@NotNull StringBuilder s)
|
<K> K |
readEvent(@NotNull Class<K> expectedClass)
Reads the next event identifier, which may be encoded as a short
string embedded in the field code, a longer string or a numeric ID,
and converts it to
expectedClass. |
@NotNull ValueIn |
readEventName(@NotNull StringBuilder name)
Reads the next field identifier into
name. |
long |
readEventNumber()
Reads a
BinaryWireCode.FIELD_NUMBER followed by a stop-bit
encoded integer representing a method or event identifier. |
protected @NotNull StringBuilder |
readFieldNumber(CharSequence keyName,
int keyCode,
@NotNull StringBuilder sb,
long fieldId)
Reads a field number from the wire and populates the provided StringBuilder.
|
@NotNull DocumentContext |
readingDocument()
Start a reading document context.
|
@NotNull DocumentContext |
readingDocument(long readLocation)
Start a reading document context from a specific position.
|
@NotNull String |
readingPeekYaml()
Typicality used for debugging, this method does not progress the read position and should
only be used when inside a reading document.
|
void |
readWithLength(@NotNull WireOut wire,
int len)
Reads data of a specified length from the bytes stream and writes to the WireOut stream
while interpreting the type of data (Map, Sequence, or Object).
|
void |
reset()
Resets this wire to its initial state, clearing bytes and document contexts
so the instance can be reused.
|
void |
rollbackIfNotComplete()
Rolls back the current operation if it is not complete.
|
BinaryWire |
setOverrideSelfDescribing(Boolean overrideSelfDescribing)
Overrides how type information is written for objects serialised by this
wire.
|
@NotNull String |
toString()
Converts the current state of the bytes storage to a debug string.
|
protected static void |
unexpectedCode()
Throw an
IORuntimeException for an unexpected code. |
protected void |
unknownCode(@NotNull WireOut wire)
Throw an
IllegalArgumentException if a code cannot be recognised. |
boolean |
useSelfDescribingMessage(@NotNull net.openhft.chronicle.bytes.CommonMarshallable object)
Determines whether a given object should use the self-describing message format.
|
@NotNull ValueOut |
write()
Writes an empty field marker to the stream.
|
@NotNull ValueOut |
write(@NotNull CharSequence key)
Writes a CharSequence key to the stream.
|
@NotNull ValueOut |
write(@NotNull WireKey key)
Writes a WireKey to the stream.
|
protected net.openhft.chronicle.bytes.Bytes<?> |
writeCode(int code)
Writes a byte code to the byte buffer.
|
@NotNull Wire |
writeComment(CharSequence s)
Writes a comment to the wire.
|
void |
writeEndEvent() |
ValueOut |
writeEventId(int methodId)
Writes an event identifier to the stream.
|
ValueOut |
writeEventId(String name,
int methodId)
Writes an event identifier with a name to the stream.
|
@NotNull ValueOut |
writeEventName(@NotNull CharSequence name)
Writes a CharSequence key to the stream.
|
@NotNull ValueOut |
writeEventName(@NotNull WireKey key)
Writes a key to the stream.
|
void |
writeStartEvent()
Start an event object, mostly for internal use.
|
@NotNull DocumentContext |
writingDocument(boolean metaData)
Begin writing a document context.
|
boolean |
writingIsComplete()
Checks if the current writing operation is complete.
|
bytes, bytesComment, classLookup, classLookup, commentListener, endOfWire, enterHeader, forceNotInsideHeader, generateTuples, generateTuples, headerNumber, headerNumber, headNumberCheck, isInsideHeader, notCompleteIsNotPresent, notCompleteIsNotPresent, objectInput, objectOutput, parent, parent, pauser, pauser, readAndSetLength, readDataHeader, readFirstHeader, readFirstHeader, readMetaDataHeader, updateFirstHeader, updateFirstHeader, updateHeader, usePadding, usePadding, writeEndOfWire, writeFirstHeaderclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgenerateTuples, generateTuples, headerNumber, newYamlWireOnHeapcommentListener, endEvent, hasMetaDataPrefix, hasMore, hintReadInputOrder, isEmpty, isEndEvent, isNotEmptyAfterPadding, objectInput, rawReadData, readAlignTo, readAllAsMap, readAndSetLength, readDataHeader, readDataHeader, readDocument, readDocument, readFirstHeader, readFirstHeader, readMetaDataHeader, startEventmethodReader, methodReaderBuilder, readBytes, readBytes, readDocument, readMap, readText, readTextdropDefault, endOfWire, enterHeader, objectOutput, padToCacheAlign, updateFirstHeader, updateFirstHeader, updateHeader, writeAlignTo, writeAllAsMap, writeDocument, writeEndOfWire, writeEvent, writeFirstHeader, writeNotCompleteDocument, writingDocumentbytes, bytesComment, classLookup, classLookup, headerNumber, notCompleteIsNotPresent, notCompleteIsNotPresent, parent, parent, pauser, pauser, usePadding, usePaddingbuilder, methodWriter, methodWriterBuilder, methodWriterBuilder, recordHistory, writeBytes, writeDocument, writeDocument, writeMap, writeMessage, writeMessage, writeText@NotNull protected final @NotNull BinaryWire.BinaryValueIn valueIn
public BinaryWire()
BinaryWire with default settings and elastic on-heap bytes.public BinaryWire(@NotNull
@NotNull net.openhft.chronicle.bytes.Bytes<?> bytes)
BinaryWire with default settings.bytes - the bytes to be processed by this wirepublic BinaryWire(@NotNull
@NotNull net.openhft.chronicle.bytes.Bytes<?> bytes,
boolean fixed,
boolean numericFields,
boolean fieldLess,
int compressedSize,
String compression)
bytes - The bytes to be processed by this wirefixed - Indicates whether the value output is fixednumericFields - Indicates if fields are represented numericallyfieldLess - Indicates if fields are absentcompressedSize - Threshold size for compressioncompression - Type of compression (e.g., "binary")@Deprecated public BinaryWire(@NotNull @NotNull net.openhft.chronicle.bytes.Bytes<?> bytes, boolean fixed, boolean numericFields, boolean fieldLess, int compressedSize, String compression, boolean supportDelta)
supportDelta parameter
which is ignored as delta wire format is not supported.bytes - The bytes to be processed by this wirefixed - Indicates whether the value output is fixednumericFields - Indicates if fields are represented numericallyfieldLess - Indicates if fields are absentcompressedSize - Threshold size for compressioncompression - Type of compression (e.g., "binary")supportDelta - must be false@NotNull public static @NotNull BinaryWire binaryOnly(@NotNull @NotNull net.openhft.chronicle.bytes.Bytes<?> bytes)
bytes - The bytes to be processed by this wirepublic void reset()
reset in interface WireCommonpublic void rollbackIfNotComplete()
RollbackIfNotCompleteNotifierDocumentContext.isNotComplete()), this
method should attempt to roll back any changes made within the current
context, effectively discarding them. If rollback is not supported or not
applicable, an UnsupportedOperationException may be thrown.rollbackIfNotComplete in interface RollbackIfNotCompleteNotifierpublic boolean isBinary()
WireCommonisBinary in interface WireCommonpublic Boolean getOverrideSelfDescribing()
null – use each object's own settingtrue – always write type informationfalse – never write type informationpublic BinaryWire setOverrideSelfDescribing(Boolean overrideSelfDescribing)
overrideSelfDescribing - see getOverrideSelfDescribing()this for chaining@NotNull protected @NotNull StringBuilder acquireStringBuilder()
@NotNull protected @NotNull BinaryWire.FixedBinaryValueOut getFixedBinaryValueOut(boolean fixed)
fixedValueOut when
fixed is true; otherwise a fresh BinaryWire.BinaryValueOut.public void clear()
clear in interface WireCommonclear in interface WireInclear in interface WireOutclear in class AbstractWirepublic boolean fieldLess()
@NotNull public @NotNull DocumentContext writingDocument(boolean metaData)
WireOut.writingDocument(boolean).
Returns a BinaryWriteDocumentContext.writingDocument in interface DocumentWrittenwritingDocument in interface MarshallableOutwritingDocument in interface WireOutmetaData - If true, the returned document context will be used for writing metadata.public DocumentContext acquireWritingDocument(boolean metaData)
WireOut.acquireWritingDocument(boolean).
Returns a BinaryWriteDocumentContext.acquireWritingDocument in interface DocumentWrittenacquireWritingDocument in interface MarshallableOutacquireWritingDocument in interface WireOutmetaData - If true, the returned context will be used for writing metadata.@NotNull public @NotNull DocumentContext readingDocument()
WireIn.readingDocument().
Returns a BinaryReadDocumentContext.readingDocument in interface MarshallableInreadingDocument in interface WireIn@NotNull public @NotNull DocumentContext readingDocument(long readLocation)
WireIn.readingDocument(long).
Returns a BinaryReadDocumentContext.readingDocument in interface WireInreadLocation - The position from which to start reading the document.@NotNull public @NotNull String readingPeekYaml()
readingPeekYaml in interface WireInpublic void copyTo(@NotNull
@NotNull WireOut wire)
throws net.openhft.chronicle.core.io.InvalidMarshallableException
wire is also a BinaryWire, bytes are copied directly;
otherwise each token is decoded and re-encoded.public void copyOne(@NotNull
@NotNull WireOut wire)
throws net.openhft.chronicle.core.io.InvalidMarshallableException
wire - The destination WireOut instance.net.openhft.chronicle.core.io.InvalidMarshallableException - if the operation encounters an error during marshalling.protected static void unexpectedCode()
throws net.openhft.chronicle.core.io.IORuntimeException
IORuntimeException for an unexpected code.net.openhft.chronicle.core.io.IORuntimeExceptionprotected void anchor(@NotNull
@NotNull WireOut wire)
unexpectedCode().wire - The wire output stream.protected void fieldAnchor(@NotNull
@NotNull WireOut wire)
wire - The wire output stream.public void readWithLength(@NotNull
@NotNull WireOut wire,
int len)
throws net.openhft.chronicle.core.io.InvalidMarshallableException
wire - The wire output stream to write data to.len - The length of data to be read.net.openhft.chronicle.core.io.InvalidMarshallableException - If there's an issue during marshalling.protected void unknownCode(@NotNull
@NotNull WireOut wire)
throws IllegalArgumentException
IllegalArgumentException if a code cannot be recognised.IllegalArgumentException@NotNull public @NotNull ValueIn read(@NotNull @NotNull String fieldName)
@NotNull public @NotNull ValueIn read()
@NotNull public @NotNull ValueIn read(@NotNull @NotNull WireKey key)
WireKey.protected <T> ValueIn read2(CharSequence keyName, int keyCode, T defaultSource, @NotNull @NotNull Function<T,Object> defaultLookup, @NotNull @NotNull net.openhft.chronicle.wire.ValueInState curr, @NotNull @NotNull StringBuilder sb, CharSequence name)
T - The type of the default source.keyName - The name of the key to be searched for.keyCode - The code corresponding to the key.defaultSource - The source to revert to if the key isn't found.defaultLookup - The function used to derive a default value based on the defaultSource.curr - The current state of ValueIn.sb - The StringBuilder used for string manipulations during search.name - The actual name of the field being sought.public long readEventNumber()
BinaryWireCode.FIELD_NUMBER followed by a stop-bit
encoded integer representing a method or event identifier. Returns
Long.MIN_VALUE if the next token is not a field number.readEventNumber in interface WireInreadEventNumber in class AbstractWire@NotNull public @NotNull ValueIn readEventName(@NotNull @NotNull StringBuilder name)
name. Returns
valueIn if a field was found or defaultValueIn if not.readEventName in interface WireInname - The StringBuilder that holds the name of the field or string.ValueIn instance.@NotNull public @NotNull ValueIn read(@NotNull @NotNull StringBuilder name)
@NotNull public @NotNull ValueIn getValueIn()
WireInWireIn.readEvent(Class).getValueIn in interface WireInValueIn instance.@NotNull public @NotNull Wire readComment(@NotNull @NotNull StringBuilder s)
readComment in interface WireIns - StringBuilder to which the comment will be appended.@Nullable
public <K> K readEvent(@NotNull
@NotNull Class<K> expectedClass)
throws net.openhft.chronicle.core.io.InvalidMarshallableException
expectedClass. Returns null if the
stream is exhausted or the code does not denote an event key.readEvent in interface WireInK - The type of object expected.expectedClass - The class type hint of the expected object. If no hint is available, use Object.class.net.openhft.chronicle.core.io.InvalidMarshallableException - If there's an error in the marshalling process.public void consumePadding()
WireInconsumePadding in interface WireInprotected int peekCode()
@NotNull protected @NotNull StringBuilder readFieldNumber(CharSequence keyName, int keyCode, @NotNull @NotNull StringBuilder sb, long fieldId)
keyName - The key name of the field to be matched against.keyCode - The key code of the field to be matched against.sb - The StringBuilder to be populated with the read field number.fieldId - The ID of the field read from the wire.@NotNull public @NotNull ValueOut write()
WireOut@NotNull public @NotNull ValueOut writeEventName(@NotNull @NotNull WireKey key)
WireOutwriteEventName in interface WireOutkey - The key to write to the stream.@NotNull public @NotNull ValueOut writeEventName(@NotNull @NotNull CharSequence name)
WireOutwriteEventName in interface WireOutname - The CharSequence key to write to the stream.public ValueOut writeEventId(int methodId)
WireOutwriteEventId in interface WireOutmethodId - The ID of the method representing the event.public ValueOut writeEventId(String name, int methodId)
WireOutwriteEventId in interface WireOutname - The name of the event.methodId - The ID of the method representing the event.public void writeStartEvent()
WireOutwriteStartEvent in interface WireOutpublic void writeEndEvent()
writeEndEvent in interface WireOut@NotNull public @NotNull ValueOut write(@NotNull @NotNull WireKey key)
WireOut@NotNull public @NotNull ValueOut write(@NotNull @NotNull CharSequence key)
WireOut@NotNull public @NotNull ValueOut getValueOut()
WireOutgetValueOut in interface WireOut@NotNull public @NotNull Wire writeComment(CharSequence s)
WireOutwriteComment in interface WireOuts - The comment to be written to the stream.@NotNull public @NotNull WireOut addPadding(int paddingToAdd)
WireOutaddPadding in interface WireOutpaddingToAdd - The amount of padding to add.protected net.openhft.chronicle.bytes.Bytes<?> writeCode(int code)
code - The byte code to write.@NotNull public @NotNull String toString()
This method provides a string representation of the bytes, useful for debugging purposes.
@NotNull public @NotNull net.openhft.chronicle.core.values.LongValue newLongReference()
WireCommonLongValue. The LongValue implementation that is
returned depends on the wire implementation.newLongReference in interface WireCommonLongValue@NotNull public @NotNull net.openhft.chronicle.core.values.BooleanValue newBooleanReference()
WireCommonBooleanValue. The BooleanValue implementation that is
returned depends on the wire implementation.newBooleanReference in interface WireCommonBooleanValue.@NotNull public @NotNull net.openhft.chronicle.core.values.TwoLongValue newTwoLongReference()
WireCommonTwoLongValue. The TwoLongValue implementation that
is returned depends on the wire implementation.newTwoLongReference in interface WireCommonTwoLongValue@NotNull public @NotNull net.openhft.chronicle.core.values.IntValue newIntReference()
WireCommonIntValue. The IntValue implementation that is
returned depends on the wire implementation.newIntReference in interface WireCommonIntValue.@NotNull public @NotNull net.openhft.chronicle.bytes.ref.BinaryLongArrayReference newLongArrayReference()
WireCommonLongArrayValues. The LongArrayValues implementation that
is returned depends on the wire implementation.newLongArrayReference in interface WireCommonLongArrayValues@NotNull public @NotNull net.openhft.chronicle.core.values.IntArrayValues newIntArrayReference()
WireCommonIntArrayValues. The IntArrayValues implementation that
is returned depends on the wire implementation.newIntArrayReference in interface WireCommonIntArrayValuespublic boolean useSelfDescribingMessage(@NotNull
@NotNull net.openhft.chronicle.bytes.CommonMarshallable object)
This method first checks if an override value for self-describing is set. If not, it uses the self-describing value from the provided object.
useSelfDescribingMessage in interface WireCommonobject - The object whose self-describing status needs to be checked.public boolean writingIsComplete()
RollbackIfNotCompleteNotifiertrue
by default, indicating completion. Implementations should override this to
reflect the actual completion status of their write operation (for
example, the inverse of DocumentContext.isNotComplete()).writingIsComplete in interface RollbackIfNotCompleteNotifierwritingIsComplete in interface WireOutCopyright © 2026 Chronicle Software Ltd. All rights reserved.