Shortcut which deserializes the value and assumes the whole ArrayBuffer for this action.
the ArrayBuffer which contains the value
This method needs to be called after all registers are done to make this serializer usable. The reason is that this serializer needs an internal IntSerializer to work which needs to be created at some point and be fitting to the number of registered serializers to be able to identify all of the indexes.
This function allows you to register serializers for the specific sub types of the union. On serialization the first fitting serializer will be used. That means that the first serializer with a true returning tester will be used.
You need to keep the order of registers the same to prevent any issue with the deserialization, since this class only prepends the index of the used serializer.
You should add the most strict type guards first and then gradually add the more general ones, since the type guards will be tested in the order in which they were added via the register method, so a broad one would be like a catch all.
There is a caveat with indistinguishable types. Two types are indistinguishable if you can assign a value from type A to a variable with type B and the other way around. Then Exclude<A, B> results in never. Which results in the next .register call to have a never as parameter type. One simple workaround is to create a property on the type which you assign a distinguishable type. In either case this can be cumbersome and is the reason the ValueSerializer has the TYPE_PINPOINT property.
The function which distinguishes between values the provided serializer can serialize and which not.
The attached Serializer.
Shortcut which creates an appropriately sized ArrayBuffer for the value and serializes the value.
the value to serialize
Generated using TypeDoc
The SwitchSerializer is meant to give you an easy to use way of serializing Union Types. You can use this serializer by defining Type Guards and assign serializers to them with the register method.
The first fitting serializer, the first serializer whose type guard returns true, will be used to delegate the serialisation and deserialization to. This class will then prepend the data by the index of the used serializer to identify the correct one on deserialization.