Documentation
¶
Overview ¶
Package hex implements hex encoding and decoding with streaming support. It provides hexadecimal encoding using the standard 16-character alphabet (0-9, A-F) for efficient binary-to-text encoding and decoding.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStreamDecoder ¶
NewStreamDecoder creates a new streaming hex decoder that reads encoded data from the provided io.Reader. The decoder uses the standard hex alphabet.
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer) io.WriteCloser
NewStreamEncoder creates a new streaming hex encoder that writes encoded data to the provided io.Writer. The encoder uses the standard hex alphabet.
Types ¶
type AlphabetSizeError ¶
type AlphabetSizeError int
AlphabetSizeError represents an error when the hex alphabet is invalid. Hex requires an alphabet of exactly 16 characters for proper encoding and decoding operations. This error occurs when the alphabet length does not meet this requirement.
func (AlphabetSizeError) Error ¶
func (e AlphabetSizeError) Error() string
Error returns a formatted error message describing the invalid alphabet length. The message includes the actual length and the required length for debugging.
type CorruptInputError ¶
type CorruptInputError int
CorruptInputError represents an error when corrupted or invalid hex data is detected during decoding. This error occurs when an invalid character is found in the input or when the input data is malformed.
func (CorruptInputError) Error ¶
func (e CorruptInputError) Error() string
Error returns a formatted error message describing the corrupted input. The message includes the position where corruption was detected.
type StdDecoder ¶
type StdDecoder struct {
Error error // Error field for storing decoding errors
}
StdDecoder represents a hex decoder for standard decoding operations. It wraps the standard library's hex decoding to provide a consistent interface with error handling capabilities.
func NewStdDecoder ¶
func NewStdDecoder() *StdDecoder
NewStdDecoder creates a new hex decoder using the standard hex alphabet.
func (*StdDecoder) Decode ¶
func (d *StdDecoder) Decode(src []byte) (dst []byte, err error)
Decode decodes the given hex-encoded byte slice back to binary data. Returns the decoded data and any error encountered during decoding. Returns an empty byte slice and nil error if the input is empty.
type StdEncoder ¶
type StdEncoder struct {
Error error // Error field for storing encoding errors
}
StdEncoder represents a hex encoder for standard encoding operations. It wraps the standard library's hex encoding to provide a consistent interface with error handling capabilities.
func NewStdEncoder ¶
func NewStdEncoder() *StdEncoder
NewStdEncoder creates a new hex encoder using the standard hex alphabet.
func (*StdEncoder) Encode ¶
func (e *StdEncoder) Encode(src []byte) (dst []byte)
Encode encodes the given byte slice using hex encoding. Returns an empty byte slice if the input is empty. The encoding process uses the standard hex alphabet (0-9, A-F).
type StreamDecoder ¶
type StreamDecoder struct { Error error // Error field for storing decoding errors // contains filtered or unexported fields }
StreamDecoder represents a streaming hex decoder that implements io.Reader. It provides efficient decoding for large data streams by processing data in chunks and maintaining an internal buffer for partial reads.
func (*StreamDecoder) Read ¶
func (d *StreamDecoder) Read(p []byte) (n int, err error)
Read implements the io.Reader interface for streaming hex decoding. Reads and decodes hex data from the underlying reader in chunks. Maintains an internal buffer to handle partial reads efficiently.
type StreamEncoder ¶
type StreamEncoder struct { Error error // Error field for storing encoding errors // contains filtered or unexported fields }
StreamEncoder represents a streaming hex encoder that implements io.WriteCloser. It provides efficient encoding for large data streams by processing data in chunks and writing encoded output immediately.
func (*StreamEncoder) Close ¶
func (e *StreamEncoder) Close() error
Close implements the io.Closer interface for streaming hex encoding. Encodes any remaining buffered bytes from the last Write call. This is the only place where we handle cross-Write state.
func (*StreamEncoder) Write ¶
func (e *StreamEncoder) Write(p []byte) (n int, err error)
Write implements the io.Writer interface for streaming hex encoding. Processes data in chunks while maintaining minimal state for cross-Write calls. This is true streaming - processes data immediately without accumulating large buffers.
Source Files
¶
- errors.go
- hex.go