Skip to content

Serde

Built-in library for:

  • serialization & deserialization
  • encoding & decoding
  • compression
local fs = require("@lune/fs")
local serde = require("@lune/serde")
-- Parse different file formats into lua tables
local someJson = serde.decode("json", fs.readFile("myFile.json"))
local someToml = serde.decode("toml", fs.readFile("myFile.toml"))
local someYaml = serde.decode("yaml", fs.readFile("myFile.yaml"))
-- Write lua tables to files in different formats
fs.writeFile("myFile.json", serde.encode("json", someJson))
fs.writeFile("myFile.toml", serde.encode("toml", someToml))
fs.writeFile("myFile.yaml", serde.encode("yaml", someYaml))

Encodes the given value using the given format.

See [EncodeDecodeFormat] for a list of supported formats.

  • format The format to use

  • value The value to encode

  • pretty If the encoded string should be human-readable, including things such as newlines and spaces. Only supported for json and toml formats, and defaults to false

  • The encoded string

Decodes the given string using the given format into a lua value.

See [EncodeDecodeFormat] for a list of supported formats.

  • format The format to use

  • encoded The string to decode

  • The decoded lua value

Compresses the given string using the given format.

See [CompressDecompressFormat] for a list of supported formats.

  • format The format to use

  • s The string to compress

  • level The compression level to use, clamped to the format’s limits. The best compression level is used by default

  • The compressed string

Decompresses the given string using the given format.

See [CompressDecompressFormat] for a list of supported formats.

  • format The format to use

  • s The string to decompress

  • The decompressed string

Hashes the given message using the given algorithm and returns the hash as a hex string.

See [HashAlgorithm] for a list of supported algorithms.

  • algorithm The algorithm to use

  • message The message to hash

  • The hash as a hex string

Hashes the given message using HMAC with the given secret and algorithm, returning the hash as a base64 string.

See [HashAlgorithm] for a list of supported algorithms.

  • algorithm The algorithm to use

  • message The message to hash

  • secret string | buffer

  • The hash as a base64 string

A serialization/deserialization format supported by the Serde library.

Currently supported formats:

NameLearn More
jsonhttps://www.json.org
yamlhttps://yaml.org
tomlhttps://toml.io

A compression/decompression format supported by the Serde library.

Currently supported formats:

NameLearn More
brotlihttps://github.com/google/brotli
gziphttps://www.gnu.org/software/gzip
lz4https://github.com/lz4/lz4
zlibhttps://www.zlib.net

A hash algorithm supported by the Serde library.

Currently supported algorithms:

NameLearn More
md5https://en.wikipedia.org/wiki/MD5
sha1https://en.wikipedia.org/wiki/SHA-1
sha224https://en.wikipedia.org/wiki/SHA-2
sha256https://en.wikipedia.org/wiki/SHA-2
sha384https://en.wikipedia.org/wiki/SHA-2
sha512https://en.wikipedia.org/wiki/SHA-2
sha3-224https://en.wikipedia.org/wiki/SHA-3
sha3-256https://en.wikipedia.org/wiki/SHA-3
sha3-384https://en.wikipedia.org/wiki/SHA-3
sha3-512https://en.wikipedia.org/wiki/SHA-3
blake3https://en.wikipedia.org/wiki/BLAKE3