encoding::hex +linux +x86_64

This module implements hexadecimal encoding and decoding.

A stream-based encoding and decoding interface is available via newencoder and newdecoder, which transparently encode or decode bytes to or from hexadecimal representation when writing to or reading from an underlying I/O handle.

Convenience functions for encoding a byte slice into a hexadecimal string or decoding from a string into a byte slice are also available; see encodestr and decodestr. These functions dynamically allocate their return values; use the stream interface if you require static allocation.

Note that writes are always encoded as lowercase hexidecimal characters, but the functions in this module can decode both upper- and lower-case hexidecimal characters.

Index

Types

// Undocumented types:
type decoder;
type encoder;

Functions

fn decodestr(str) ([]u8 | io::error);
fn dump(io::handle, []u8) (void | io::error);
fn encode(io::handle, []u8) (size | io::error);
fn encodestr([]u8) str;
fn newdecoder(io::handle) decoder;
fn newencoder(io::handle) encoder;

Types

type decoder[link]

Show undocumented member
type decoder = struct {
	stream: io::stream,
	in: io::handle,
	state: (void | io::EOF | io::error),
};

type encoder[link]

Show undocumented member
type encoder = struct {
	stream: io::stream,
	out: io::handle,
	err: (void | io::error),
};

Functions

fn decodestr[link]

fn decodestr(s: str) ([]u8 | io::error);

Decodes a string of hexadecimal bytes into a byte slice. The caller must free the return value.

fn dump[link]

fn dump(out: io::handle, data: []u8) (void | io::error);

Outputs a dump of hex data alongside the offset and an ASCII representation (if applicable).

Example output:

00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  03 00 3e 00 01 00 00 00  80 70 01 00 00 00 00 00  |..>......p......|

fn encode[link]

fn encode(out: io::handle, in: []u8) (size | io::error);

Encodes a byte slice as a hexadecimal string and writes it to an io::handle.

fn encodestr[link]

fn encodestr(in: []u8) str;

Encodes a byte slice as a hexadecimal string and returns it. The caller must free the return value.

fn newdecoder[link]

fn newdecoder(in: io::handle) decoder;

Creates a stream that reads and decodes hexadecimal data from a secondary stream. This stream does not need to be closed, and closing it will not close the underlying stream.

fn newencoder[link]

fn newencoder(out: io::handle) encoder;

Creates a stream that encodes writes as lowercase hexadecimal before writing them to a secondary stream. Closing this stream will not close the underlying stream.