Encoder
An Encoder is an isolated encode/decode context. Each instance carries
its own table of custom per-type encoders, so two encoders configured
differently can co-exist without interfering with each other or with the
module-level Bufferize.encode / Bufferize.decode functions.
Create one with Bufferize.custom:
local myEncoder = Bufferize.custom()
myEncoder:override("Color3", { read = ..., write = ... })
local b = myEncoder:encode(Color3.new(1, 0, 0))
local color = myEncoder:decode(b)
A buffer produced by an Encoder with overrides can only be decoded by an
encoder configured with the same overrides — there is no way to recover the
override information from the buffer alone.
Properties
VERSION
Encoder.VERSION: stringThe semantic version string of the running Bufferize module. Mirrors Bufferize.VERSION.
Functions
new
Creates a new encoder with no overrides registered. Prefer calling this via Bufferize.custom for clarity at the call site.
readVersion
Encoder.readVersion(b: buffer--
A buffer previously produced by an encoder's encode method.
) → string?--
The semantic version string written into the header, or nil if it could not be parsed.
Reads the Bufferize version stored in the buffer's header without decoding the body. See Bufferize.readVersion.
override
Encoder:override(typeOf: string,--
The typeof name of the data type to override (e.g. "CFrame", "Color3").
encoder: {read: (buffer) → T,write: (T) → buffer}--
A pair of conversion functions between the data type and a buffer.
) → ()Registers a custom read/write pair for the given data type on this encoder. The same override must be present on whichever encoder decodes the buffer later — there is no way to recover it from the buffer itself.
Attempting to override a type that is not overridable raises an error.
encode
Encoder:encode(...: Supported--
One or more values of supported data types.
) → buffer--
A buffer that round-trips through this encoder's decode to the same values.
Encodes the given values into a buffer, applying any overrides registered via Encoder:override. The buffer is prefixed with the running Bufferize version.
decode
Encoder:decode(b: buffer--
A buffer previously produced by this encoder (or one with the same overrides).
) → ...Supported--
The original values, in the same order they were passed to encode.
Decodes a buffer produced by encode. Raises an error if the buffer was
encoded with an incompatible major version, or with a newer version of
Bufferize than the one currently loaded.