Module eco.encoding.hex
Hex encoding/decoding utilities.
This module provides helpers to encode raw bytes into lowercase hexadecimal
strings, decode hex strings back into raw bytes, and format a hexdump similar
to hexdump -C.
Functions
| encode (bin[, sep='']) | Encode bytes to a hexadecimal string. |
| decode (s) | Decode a hexadecimal string into bytes. |
| dump (data) | Format a hexdump of the given data. |
Functions
- encode (bin[, sep=''])
-
Encode bytes to a hexadecimal string.
Parameters:
Returns:
-
string
Lowercase hexadecimal string.
- decode (s)
-
Decode a hexadecimal string into bytes.
On malformed input, returns
nil, 'input is malformed'.Parameters:
- s string Hex string.
Returns:
-
string
out Decoded bytes.
Or
- nil On malformed input.
- string Error message.
- dump (data)
-
Format a hexdump of the given data.
The format matches the output of
hexdump -C.Parameters:
- data string Input bytes.
Returns:
-
string
Dump string (contains newlines).
Usage:
local hex = require 'eco.encoding.hex' print(hex.dump('hello'))