The type of value this type can write (presumably a recursive value)
The type of value this type will read
The name of the type, as registered using registerType
Requires that the buffer be a GrowableBuffer or AppendableStream
The value to assert is an AppendableBuffer
Determines whether the input is a Type with the same class
A value, usually a Type instance
whether this
and otherType
are instances of the same Type class
An alternative to registerType, to avoid writing the type's name twice. Please use this instead of registerType.
So this
let type = new sb.RecursiveType('abc')
sb.registerType({
type: new sb.StructType({
//...
}),
name: 'abc'
})
becomes
let type = new sb.RecursiveType('abc')
type.setType(new sb.StructType({
//...
}))
The type to register
Appends value bytes to an AppendableBuffer according to the type
Example:
treeType.writeValue(buffer, {
left: {
left: {value: 1},
value: 2,
right: {value: 3}
},
value: 4,
right: {
value: 5,
right: {value: 6}
}
})
The buffer to which to append
The value to write
Generated using TypeDoc
A type that can refer recursively to itself. This is not a type in its own right, but allows you to have some other type use itself in its definition. Values that contain circular references will have the references preserved after serialization and deserialization.
Note that it is impossible to create self-referencing types any other way, due to the immutable nature of types. Also, other types will infinitely recurse on writes with circular references.
Recursive types must be of one of the following types:
This is due to the way that recursive values are deserialized. For example, say the value was created with the following code:
In order to deserialize the value, we need to carry out the same process:
self
field, which gives the base valueself
field, mutating the base valueThe base values used are as follows:
[]
for ArrayType and TupleTypenew Map
for MapTypenew Set
for SetType{}
for StructTypeBase values for other types are harder to compute, which is why they are not allowed as RecursiveTypes. You can always use another type by making it the sole field of a StructType.
Example: