Skip to main content

BinaryClassSerializationAdapter

BinaryClassSerializationAdapter

Defines how to serialize and deserialize an instance of a given class. This class is intended to be overridden.

Kind: global class
Author: Alex Goldring
Copyright: Company Named Limited (c) 2025

new exports.BinaryClassSerializationAdapter()

Example

class BookSerializer extends BinaryClassSerializationAdapter{
klass = Book
version = 0

serialize(buffer: BinaryBuffer, book: Book){

buffer.writeUTF8String(book.title);
buffer.writeUint32(book.page_count);
buffer.writeUTF8String(book.text);

}

deserialize(buffer: BinaryBuffer, book: Book){

book.title = buffer.readUTF8String();
book.page_count = buffer.readUint32();
book.text = buffer.readUTF8String();

}
}

binaryClassSerializationAdapter.klass : Class.<T>

Class that this adapter handles. NOTE: misspelling of the word "class" is intentional, in JavaScript "class" is a reserved word.

Kind: instance property of BinaryClassSerializationAdapter
Access: protected
Example

klass = Vector3

binaryClassSerializationAdapter.version : number

Format version number, used to check for format changes and data compatibility Increment the number if you change the adapter to indicate the change in format See BinaryClassUpgrader for details on how to handle support for outdated format versions

Kind: instance property of BinaryClassSerializationAdapter
Access: protected

binaryClassSerializationAdapter.isBinaryClassSerializationAdapter : boolean

Kind: instance property of BinaryClassSerializationAdapter
Read only: true

binaryClassSerializationAdapter.initialize(...args)

Invoked externally as part of the serialization lifecycle. Guaranteed to be invoked before the first usage of the adapter.

Kind: instance method of BinaryClassSerializationAdapter

Param
...args

binaryClassSerializationAdapter.finalize()

Handle any necessary resource cleanup. Invoked externally as part of the serialization lifecycle Guaranteed to be invoked after the last usage of the adapter.

Kind: instance method of BinaryClassSerializationAdapter

binaryClassSerializationAdapter.serialize(buffer, value)

Serialize an instance into the passed buffer. Will write at the current BinaryBuffer.position.

Kind: instance method of BinaryClassSerializationAdapter

ParamType
bufferBinaryBuffer
valueT

binaryClassSerializationAdapter.deserialize(buffer, value)

Read value from the buffer, passed in value will change as a result. Will read from the current BinaryBuffer.position.

Kind: instance method of BinaryClassSerializationAdapter

ParamType
bufferBinaryBuffer
valueT