Class BooleanCodec

java.lang.Object
io.bytestreams.codec.core.BooleanCodec
All Implemented Interfaces:
Codec<Boolean>

public class BooleanCodec extends Object implements Codec<Boolean>
A codec for boolean values encoded as a single byte.

Encodes false as 0x00 and true as 0x01. Decoding is strict: any value other than 0x00 or 0x01 throws a CodecException.

  • Constructor Details

    • BooleanCodec

      public BooleanCodec()
  • Method Details

    • encode

      public EncodeResult encode(Boolean value, OutputStream output) throws IOException
      Description copied from interface: Codec
      Encodes the given value and writes it to the output stream.
      Specified by:
      encode in interface Codec<Boolean>
      Parameters:
      value - the value to encode
      output - 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

      public Boolean decode(InputStream input) throws IOException
      Description copied from interface: Codec
      Decodes a value from the input stream.
      Specified by:
      decode in interface Codec<Boolean>
      Parameters:
      input - the input stream to read the encoded bytes from
      Returns:
      the decoded value
      Throws:
      IOException - if an I/O error occurs during decoding