Package io.bytestreams.codec.core
Class ConstantCodec
java.lang.Object
io.bytestreams.codec.core.ConstantCodec
- All Implemented Interfaces:
Codec<byte[]>,Inspectable<byte[]>
A codec for constant byte sequences such as magic numbers, version bytes, and protocol
signatures.
On encode, always writes the expected bytes (ignoring the input value). On decode, reads and
validates that the bytes match the expected value, throwing CodecException on mismatch.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]decode(InputStream input) Decodes a value from the input stream.encode(byte[] value, OutputStream output) Encodes the given value and writes it to the output stream.inspect(byte[] value) Returns the expected constant bytes regardless of the input value.
-
Method Details
-
encode
Encodes the given value and writes it to the output stream.Ignores the input value and always writes the expected constant bytes.
- Specified by:
encodein interfaceCodec<byte[]>- Parameters:
value- the value to encodeoutput- the output stream to write the encoded bytes to- Returns:
- the encode result containing logical count and bytes written
- Throws:
IOException- if an I/O error occurs during encoding
-
decode
Decodes a value from the input stream.- Specified by:
decodein interfaceCodec<byte[]>- Parameters:
input- the input stream to read the encoded bytes from- Returns:
- the decoded value
- Throws:
CodecException- if the decoded bytes do not match the expected constantEOFException- if the stream ends before the required bytes are readIOException- if an I/O error occurs during decoding
-
inspect
Returns the expected constant bytes regardless of the input value.- Specified by:
inspectin interfaceInspectable<byte[]>- Parameters:
value- the decoded value to inspect- Returns:
- a structured representation (Map, List, or scalar)
-