encoding::hex+x86_64 +linux
hex: hexadecimal encoding and decoding support
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 hexadecimal characters, but the functions in this module can decode both upper- and lower-case hexadecimal characters.
Index
Types
// Undocumented types: type decoder; type encoder;
Functions
fn decodestr(s: str) ([]u8 | errors::invalid | nomem); fn dump(out: io::handle, data: []u8, addr: u64 = 0) (void | io::error); fn encode(out: io::handle, in: []u8) (size | io::error); fn encodestr(in: []u8) (str | nomem); fn newdecoder(in: io::handle) decoder; fn newencoder(out: io::handle) encoder;
Types
type decoder[permalink] [source]
Show undocumented member
type decoder = struct { stream: io::stream, in: io::handle, state: (void | io::EOF | io::error), };
type encoder[permalink] [source]
Show undocumented member
type encoder = struct { stream: io::stream, out: io::handle, err: (void | io::error), };
Functions
fn decodestr[permalink] [source]
fn decodestr(s: str) ([]u8 | errors::invalid | nomem);
Decodes a string of hexadecimal bytes into a byte slice. The caller must free the return value.
fn dump[permalink] [source]
fn dump(out: io::handle, data: []u8, addr: u64 = 0) (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......|
If the addr parameter is provided, the address column will start from this address (but the data slice will still be printed from index 0).
fn encode[permalink] [source]
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[permalink] [source]
fn encodestr(in: []u8) (str | nomem);
Encodes a byte slice as a hexadecimal string and returns it. The caller must free the return value.
fn newdecoder[permalink] [source]
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[permalink] [source]
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.