Component Serialization
Replecs.Serdes
Section titled “Replecs.Serdes”Serializes a component value into a buffer. Set with replicator:set_serdes() or the replecs.serdes component.
Serdes take part in the handshake, so the server and client must set a matching one.
See the component serialization guide.
type Serdes<T> = { serialize: (value: T) -> (buffer, { any }?), deserialize: (buf: buffer, variants: { any }?) -> T,
bytespan: number?, includes_variants: boolean?,}Fields
Section titled “Fields”- bytespan: Fixed length of the serialized buffer. When set, the length is not written into the packet.
- includes_variants: Whether
serializereturns extra values that can’t be written into the buffer.
Functions (Not Methods)
Section titled “Functions (Not Methods)”-
serialize(): Serializes the component value into a buffer.
- Arguments
- value: The component value.
- Returns
- buf: The serialized buffer.
- variants: Values to send as is, only if
includes_variantsistrue.
- Arguments
-
deserialize(): Rebuilds the component value from the buffer.
- Arguments
- buf: The serialized buffer.
- variants: The values returned by
serialize, only ifincludes_variantsistrue.
- Returns
- value: The component value.
- Arguments
Replecs.Preprocessor
Section titled “Replecs.Preprocessor”Transforms a component value before it is serialized, and back after it is deserialized.
Set with replicator:set_preprocessor(). In the server it runs before the serdes, in the client it runs after.
The handshake only checks that both sides have a preprocessor for the same components, not what they do, so make sure the server and client set a matching one. See the component serialization guide.
type Preprocessor<B, A> = { serialize: (value: B) -> A, deserialize: (value: A) -> B,}Functions (Not Methods)
Section titled “Functions (Not Methods)”-
serialize(): Transforms the component value into the value to replicate.
- Arguments
- value: The component value.
- Returns
- value: The value to replicate.
- Arguments
-
deserialize(): Transforms the replicated value back into the component value.
- Arguments
- value: The replicated value.
- Returns
- value: The component value.
- Arguments