Package com.abovevacant.epitaph.io
Class WireReader
java.lang.Object
com.abovevacant.epitaph.io.WireReader
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidexpectWireType(int fieldNumber, int expected, int actual) Validates that the actual wire type matches the expected wire type.static WireReaderfromInputStream(InputStream stream) Creates a WireReader from an InputStream by reading all bytes.static intgetFieldNumber(int tag) Extracts the field number from a tag.static intgetWireType(int tag) Extracts the wire type from a tag.booleanbooleanreadBool()Reads a boolean (as varint).byte[]Reads a length-delimited field as raw bytes.intReads a 32-bit fixed value (little-endian).longReads a 64-bit fixed value (little-endian).Creates a sub-reader for an embedded message.Reads a length-delimited field as a UTF-8 string.intreadTag()Reads a tag (field number + wire type).longReads a varint (variable-length integer).intReads a 32-bit varint.intvoidskipField(int wireType) Skips a field based on its wire type.
-
Field Details
-
WIRETYPE_VARINT
public static final int WIRETYPE_VARINT- See Also:
-
WIRETYPE_FIXED64
public static final int WIRETYPE_FIXED64- See Also:
-
WIRETYPE_LENGTH_DELIMITED
public static final int WIRETYPE_LENGTH_DELIMITED- See Also:
-
WIRETYPE_FIXED32
public static final int WIRETYPE_FIXED32- See Also:
-
-
Constructor Details
-
WireReader
public WireReader(byte[] data) -
WireReader
public WireReader(byte[] data, int offset, int length)
-
-
Method Details
-
fromInputStream
Creates a WireReader from an InputStream by reading all bytes.- Throws:
IOException
-
hasRemaining
public boolean hasRemaining() -
remaining
public int remaining() -
readTag
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
Reads a varint (variable-length integer).varints use 7 bits per byte, with the MSB indicating continuation.
- Throws:
IOException
-
readVarInt32
Reads a 32-bit varint.- Throws:
IOException
-
readFixed64
Reads a 64-bit fixed value (little-endian).- Throws:
IOException
-
readFixed32
Reads a 32-bit fixed value (little-endian).- Throws:
IOException
-
readBytes
Reads a length-delimited field as raw bytes.- Throws:
IOException
-
readString
Reads a length-delimited field as a UTF-8 string.- Throws:
IOException
-
readBool
Reads a boolean (as varint).- Throws:
IOException
-
readMessage
Creates a sub-reader for an embedded message.- Throws:
IOException
-
expectWireType
Validates that the actual wire type matches the expected wire type.- Parameters:
fieldNumber- the field number (for error messages)expected- the expected wire typeactual- the actual wire type from the tag- Throws:
IOException- if the wire types don't match
-
skipField
Skips a field based on its wire type.- Throws:
IOException
-