@eryx/encoding/hex Module

JSON

Hexadecimal encoding utilities.

Encodes binary buffer data into lowercase hexadecimal strings and decodes hex strings back into buffers. Both uppercase and lowercase hex digits are accepted when decoding.

local hex = require("@eryx/encoding/hex")
local encoded = hex.encode(buffer.fromstring("\xff\x0a"))
print(encoded) -- "ff0a"

Summary

Functions

hex.encode(buf: buffer | string)string
hex.decode(str: string)buffer

API Reference

Functions

hex.encode

Encodes a buffer into a lowercase hexadecimal string.

hex.encode(buf: buffer | string)string

Parameters

buf: buffer | string

The binary data to encode.

Returns

string

The hex-encoded string (always lowercase).

hex.decode

Decodes a hexadecimal string back into a buffer.

Accepts both uppercase (A–F) and lowercase (a–f) hex digits. The input string length must be even.

hex.decode(str: string)buffer

Parameters

str: string

The hex-encoded string.

Returns

buffer

The decoded binary data.