Class WireReader

java.lang.Object
com.abovevacant.epitaph.io.WireReader

public final class WireReader extends Object
Low-level protobuf wire format reader.

Supports reading:

  • Wire type 0: varint (int32, int64, uint32, uint64, bool, enum)
  • Wire type 1: 64-bit fixed
  • Wire type 2: Length-delimited (string, bytes, embedded messages)
  • Wire type 5: 32-bit fixed
  • Field Details

  • Constructor Details

    • WireReader

      public WireReader(byte[] data)
    • WireReader

      public WireReader(byte[] data, int offset, int length)
  • Method Details

    • fromInputStream

      public static WireReader fromInputStream(InputStream stream) throws IOException
      Creates a WireReader from an InputStream by reading all bytes.
      Throws:
      IOException
    • hasRemaining

      public boolean hasRemaining()
    • remaining

      public int remaining()
    • readTag

      public int readTag() throws IOException
      Reads a tag (field number + wire type).
      Returns:
      the tag value, or 0 if at end of data
      Throws:
      IOException
    • getFieldNumber

      public static int getFieldNumber(int tag)
      Extracts the field number from a tag.
    • getWireType

      public static int getWireType(int tag)
      Extracts the wire type from a tag.
    • readVarInt

      public long readVarInt() throws IOException
      Reads a varint (variable-length integer).

      varints use 7 bits per byte, with the MSB indicating continuation.

      Throws:
      IOException
    • readVarInt32

      public int readVarInt32() throws IOException
      Reads a 32-bit varint.
      Throws:
      IOException
    • readFixed64

      public long readFixed64() throws IOException
      Reads a 64-bit fixed value (little-endian).
      Throws:
      IOException
    • readFixed32

      public int readFixed32() throws IOException
      Reads a 32-bit fixed value (little-endian).
      Throws:
      IOException
    • readBytes

      public byte[] readBytes() throws IOException
      Reads a length-delimited field as raw bytes.
      Throws:
      IOException
    • readString

      public String readString() throws IOException
      Reads a length-delimited field as a UTF-8 string.
      Throws:
      IOException
    • readBool

      public boolean readBool() throws IOException
      Reads a boolean (as varint).
      Throws:
      IOException
    • readMessage

      public WireReader readMessage() throws IOException
      Creates a sub-reader for an embedded message.
      Throws:
      IOException
    • expectWireType

      public static void expectWireType(int fieldNumber, int expected, int actual) throws IOException
      Validates that the actual wire type matches the expected wire type.
      Parameters:
      fieldNumber - the field number (for error messages)
      expected - the expected wire type
      actual - the actual wire type from the tag
      Throws:
      IOException - if the wire types don't match
    • skipField

      public void skipField(int wireType) throws IOException
      Skips a field based on its wire type.
      Throws:
      IOException