rbxl

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 18 Imported by: 5

README

rbxfile/rbxl

GoDoc

Package rbxl implements a decoder and encoder for Roblox's binary file format.

This package registers the formats "rbxl" and "rbxm" to the rbxfile package.

The easiest way to decode and encode files is through the functions DeserializePlace, SerializePlace, DeserializeModel, and SerializeModel. These decode and encode directly between byte streams and Root structures specified by the rbxfile package. For most purposes, this is all that is required to read and write Roblox binary files. Further documentation gives an overview of how the package works internally.

Overview

A Serializer is used to transform data from byte streams to Root structures and back. A serializer specifies a decoder and encoder. Both a decoder and encoder combined is referred to as a "codec".

Codecs transform data between a generic rbxfile.Root structure, and this package's "format model" structure. Custom codecs can be implemented. For example, you might wish to decode files normally, but encode them in an alternative way:

serializer := NewSerializer(nil, CustomEncoder)

Custom codecs can be used with a Serializer by implementing the Decoder and Encoder interfaces. Both do not need to be implemented. In the example above, passing nil as an argument causes the serializer to use the default "RobloxCodec", which implements both a default decoder and encoder. This codec attempts to emulate how Roblox decodes and encodes its files.

A FormatModel is the representation of the file format itself, rather than the data it contains. The FormatModel is like a buffer between the byte stream and the Root structure. FormatModels can be encoded (and rarely, decoded) to and from Root structures in multiple ways, which is specified by codecs. However, there is only one way to encode and decode to and from a byte stream, which is handled by the FormatModel.

Documentation

Overview

Package rbxl implements a decoder and encoder for Roblox's binary file format.

Index

Constants

This section is empty.

Variables

View Source
var ErrXML = errors.New("unexpected XML format")

ErrXML indicates the unexpected detection of the legacy XML format.

Functions

This section is empty.

Types

type ChunkError added in v0.4.0

type ChunkError struct {
	// Index is the position of the chunk within the file.
	Index int
	// Sig is the signature of the chunk.
	Sig sig

	Cause error
}

ChunkError indicates an error that occurred within a chunk.

func (ChunkError) Error added in v0.4.0

func (err ChunkError) Error() string

func (ChunkError) Unwrap added in v0.4.0

func (err ChunkError) Unwrap() error

type CodecError added in v0.4.0

type CodecError struct {
	Cause error
}

CodecError wraps an error that occurred while encoding or decoding a binary format model.

func (CodecError) Error added in v0.4.0

func (err CodecError) Error() string

func (CodecError) Unwrap added in v0.4.0

func (err CodecError) Unwrap() error

type DataError added in v0.4.0

type DataError struct {
	// Offset is the byte offset where the error occurred.
	Offset int64

	Cause error
}

DataError wraps an error that occurred while encoding or decoding byte data.

func (DataError) Error added in v0.4.0

func (err DataError) Error() string

func (DataError) Unwrap added in v0.4.0

func (err DataError) Unwrap() error

type Decoder

type Decoder struct {
	// Mode indicates which type of format is decoded.
	Mode Mode

	// If NoXML is true, then the decoder will not attempt to decode the legacy
	// XML format for backward compatibility.
	NoXML bool

	// If not nil, stats will be set while decoding.
	Stats *DecoderStats
}

Decoder decodes a stream of bytes into an rbxfile.Root.

func (Decoder) Decode

func (d Decoder) Decode(r io.Reader) (root *rbxfile.Root, warn, err error)

Decode reads data from r and decodes it into root according to the rbxl format.

func (Decoder) Decompress added in v0.4.0

func (d Decoder) Decompress(w io.Writer, r io.Reader) (warn, err error)

Decompress reencodes the compressed chunks of the binary format as uncompressed. The format is decoded from r, then encoded to w.

Returns ErrXML if the the data is in the legacy XML format.

func (Decoder) Dump added in v0.4.0

func (d Decoder) Dump(w io.Writer, r io.Reader) (warn, err error)

Dump writes to w a readable representation of the binary format decoded from r.

Returns ErrXML if the the data is in the legacy XML format.

type DecoderStats added in v0.6.2

type DecoderStats struct {
	XML           bool           // Whether the format is XML.
	Version       uint16         // Version of the format.
	ClassCount    uint32         // Number of classes reported by the header.
	InstanceCount uint32         // Number of instances reported by the header.
	Chunks        int            // Total number of chunks.
	ChunkTypes    map[string]int // Number of chunks per signature.
}

DecoderStats contains statistics generated while decoding the format.

type Encoder

type Encoder struct {
	// Mode indicates which type of format is encoded.
	Mode Mode

	// Uncompressed sets whether compression is forcibly disabled for all
	// chunks.
	Uncompressed bool
}

Encoder encodes a rbxfile.Root into a stream of bytes.

func (Encoder) Encode

func (e Encoder) Encode(w io.Writer, root *rbxfile.Root) (warn, err error)

Encode formats root according to the rbxl format, and writers it to w.

type Mode

type Mode uint8

Mode indicates how the codec formats data.

const (
	Place Mode = iota // Data is handled as a Roblox place (RBXL) file.
	Model             // Data is handled as a Roblox model (RBXM) file.
)

type ValueError added in v0.4.0

type ValueError struct {
	Type byte

	Cause error
}

ValueError is an error that is produced by a Value of a certain Type.

func (ValueError) Error added in v0.4.0

func (err ValueError) Error() string

func (ValueError) Unwrap added in v0.4.0

func (err ValueError) Unwrap() error

type XMLError added in v0.4.0

type XMLError struct {
	Cause error
}

XMLError wraps an error that occurred while parsing the legacy XML format.

func (XMLError) Error added in v0.4.0

func (err XMLError) Error() string

func (XMLError) Unwrap added in v0.4.0

func (err XMLError) Unwrap() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL