@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
92 lines (82 loc) • 2.25 kB
JavaScript
/**
* Defines how to serialize and deserialize an instance of a given class
*
* @template T
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class BinaryClassSerializationAdapter {
/**
* Class that this adapter handles
* @protected
* @type {Class<T>}
*/
klass = null;
/**
* 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 {@link BinaryClassUpgrader} for details on how to handle support for outdated format versions
* @protected
* @type {number}
*/
version = 0;
/**
* @deprecated use {@link this.klass}
* @returns {Class<T>}
*/
getClass() {
return this.klass;
}
/**
* @deprecated use {@link this.version}
*
* @returns {number}
*/
getVersion() {
return this.version;
}
/**
* Invoked externally as part of the serialization lifecycle.
* Guaranteed to be invoked before the first usage of the adapter.
*
* @param args
*/
initialize(...args) {
//override as needed
}
/**
* Handle any necessary resource cleanup.
* Invoked externally as part of the serialization lifecycle
* Guaranteed to be invoked after the last usage of the adapter.
*
*/
finalize() {
//override as need
}
/**
* Serialize an instance into the passed buffer.
* Will write at the current {@link BinaryBuffer.position}.
*
* @param {BinaryBuffer} buffer
* @param {T} value
*/
serialize(buffer, value) {
//override as necessary
}
/**
* Read value from the buffer, passed in value will change as a result.
* Will read from the current {@link BinaryBuffer.position}.
*
* @param {BinaryBuffer} buffer
* @param {T} value
*/
deserialize(buffer, value) {
//override as necessary
}
}
/**
* @readonly
* @type {boolean}
*/
BinaryClassSerializationAdapter.prototype.isBinaryClassSerializationAdapter = true;