Class BinaryWire

java.lang.Object
io.fluxzero.common.api.internal.BinaryWire

public final class BinaryWire extends Object
Allocation-bounded primitive I/O shared by compact transports and persisted messages.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Unchecked cursor for validated embedded values whose public API does not expose I/O failures.
    static final class 
     
    static final class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    bytesSize(byte[] value)
    Returns the encoded size of one nullable length-prefixed byte array.
    decodeEnvelope(byte[] bytes, int maximumValueSize)
    Decodes exactly one native message envelope while retaining zero-copy payload and metadata views.
    decodeEnvelope(byte[] bytes, int offset, int length, int maximumValueSize)
    Decodes exactly one envelope from a byte range, retaining zero-copy payload and metadata views.
    decodeEnvelopes(byte[] bytes, int maximumValueSize)
    Decodes a sequence while retaining zero-copy payload and metadata views.
    decodeEnvelopes(byte[] bytes, int offset, int length, int maximumValueSize)
    Decodes a native-envelope sequence from a byte range.
    static byte[]
    Encodes one native message envelope.
    static byte[]
    Encodes a sequence of concatenated native message envelopes.
    static int
    Returns the complete encoded size of one native message envelope.
    static boolean
    isEnvelopeSequence(byte[] bytes)
    Returns whether the byte sequence starts with this codec's native-envelope signature.
    static boolean
    isEnvelopeSequence(byte[] bytes, int offset, int length)
    Returns whether a byte range starts with this codec's native-envelope signature.
    static int
    longsSize(long[] values)
    Returns the encoded size of one nullable length-prefixed long array.
    static int
    Returns the size of a native envelope when embedded as one length-delimited wire value.
    static int
    Returns the encoded size of one nullable long.
    static int
    peekInt(byte[] bytes, int offset)
    Reads a big-endian 32-bit integer at the supplied offset without maintaining or advancing a cursor.
    Prepares a message once for reuse by an enclosing transport codec.
    Prepares a message sequence, retaining the original list when every envelope is reusable.
    static Long
    readEnvelopeIndex(byte[] bytes, int offset, int length, int maximumValueSize)
    Reads only the indexed routing field from one native message without materializing application data.
    static int
    readEnvelopeSize(byte[] bytes, int offset, int length, int maximumValueSize)
    Returns the complete size of the next native message envelope in a byte range.
    static int
    Returns the encoded size of one nullable length-prefixed UTF-8 string.
    static boolean
    utf8Equals(byte[] bytes, int offset, int byteLength, String value)
    Compares the selected byte region with the UTF-8 encoding of the value without allocating encoded bytes; unpaired surrogates are compared as question marks.
    static int
    Returns the UTF-8 byte length without allocating encoded bytes, or -1 for null.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • peekInt

      public static int peekInt(byte[] bytes, int offset)
      Reads a big-endian 32-bit integer at the supplied offset without maintaining or advancing a cursor.
    • utf8Length

      public static int utf8Length(String value)
      Returns the UTF-8 byte length without allocating encoded bytes, or -1 for null. Unpaired surrogates use a one-byte replacement; length overflow throws ArithmeticException.
    • stringSize

      public static int stringSize(String value)
      Returns the encoded size of one nullable length-prefixed UTF-8 string.
    • nullableLongSize

      public static int nullableLongSize(Long value)
      Returns the encoded size of one nullable long.
    • bytesSize

      public static int bytesSize(byte[] value)
      Returns the encoded size of one nullable length-prefixed byte array.
    • longsSize

      public static int longsSize(long[] values)
      Returns the encoded size of one nullable length-prefixed long array.
    • envelopeSize

      public static int envelopeSize(SerializedMessage message)
      Returns the complete encoded size of one native message envelope.
    • nestedEnvelopeSize

      public static int nestedEnvelopeSize(SerializedMessage message)
      Returns the size of a native envelope when embedded as one length-delimited wire value.
    • prepareEnvelope

      public static SerializedMessage prepareEnvelope(SerializedMessage message)
      Prepares a message once for reuse by an enclosing transport codec.
    • prepareEnvelopes

      public static List<SerializedMessage> prepareEnvelopes(List<SerializedMessage> messages)
      Prepares a message sequence, retaining the original list when every envelope is reusable.
    • encodeEnvelopes

      public static byte[] encodeEnvelopes(List<SerializedMessage> messages)
      Encodes a sequence of concatenated native message envelopes.
    • encodeEnvelope

      public static byte[] encodeEnvelope(SerializedMessage message)
      Encodes one native message envelope.
    • decodeEnvelope

      public static SerializedMessage decodeEnvelope(byte[] bytes, int maximumValueSize) throws IOException
      Decodes exactly one native message envelope while retaining zero-copy payload and metadata views.
      Throws:
      IOException
    • decodeEnvelope

      public static SerializedMessage decodeEnvelope(byte[] bytes, int offset, int length, int maximumValueSize) throws IOException
      Decodes exactly one envelope from a byte range, retaining zero-copy payload and metadata views.
      Throws:
      IOException
    • decodeEnvelopes

      public static List<SerializedMessage> decodeEnvelopes(byte[] bytes, int maximumValueSize) throws IOException
      Decodes a sequence while retaining zero-copy payload and metadata views.
      Throws:
      IOException
    • decodeEnvelopes

      public static List<SerializedMessage> decodeEnvelopes(byte[] bytes, int offset, int length, int maximumValueSize) throws IOException
      Decodes a native-envelope sequence from a byte range.
      Throws:
      IOException
    • isEnvelopeSequence

      public static boolean isEnvelopeSequence(byte[] bytes)
      Returns whether the byte sequence starts with this codec's native-envelope signature.
    • isEnvelopeSequence

      public static boolean isEnvelopeSequence(byte[] bytes, int offset, int length)
      Returns whether a byte range starts with this codec's native-envelope signature.
    • readEnvelopeSize

      public static int readEnvelopeSize(byte[] bytes, int offset, int length, int maximumValueSize) throws IOException
      Returns the complete size of the next native message envelope in a byte range.
      Throws:
      IOException
    • readEnvelopeIndex

      public static Long readEnvelopeIndex(byte[] bytes, int offset, int length, int maximumValueSize) throws IOException
      Reads only the indexed routing field from one native message without materializing application data.
      Throws:
      IOException
    • utf8Equals

      public static boolean utf8Equals(byte[] bytes, int offset, int byteLength, String value)
      Compares the selected byte region with the UTF-8 encoding of the value without allocating encoded bytes; unpaired surrogates are compared as question marks.