Optional
relation: PrimitiveSymbol | InstantiableObject<Target>Defines the property type as either a primitive, a nested type definition, or null in case of an unknown property.
Optional
args: RelationParameters<This, Args>Optional arguments passed to the nested type definition.
The property decorator function.
The most basic usage of the @Relation
is to define the primitive type of
the decorated property.
In the following example a basic format definition is written that defines
the data
property as an unsigned 8 bit integer.
class Protocol {
@Relation(PrimitiveSymbol.u8)
data: number
}
The @Relation
decorator can also be used to refer to a nested structure.
In the following example the Protocol
format definition refers to the
Coord
definition with the @Relation
decorator.
This will result in a nested object accessible through the property
data
.
class Coord {
@Relation(PrimitiveSymbol.i16)
x: number
@Relation(PrimitiveSymbol.i16)
y: number
}
class Protocol {
@Relation(Coord)
data: number
}
It's also possible to use @Relation
decorator to pass arguments to the
nested object relation.
class SubProtocol {
_count: number
constructor(count: number) {
this._count = count
}
}
class Protocol {
@Relation(PrimitiveType.u8)
count: number
// Can refer to the argument just with a string
// to pass multiple arguments you can use comma-separeted references.
@Relation(SubProtocol, 'count')
sub: SubProtocol
// Using function is also possible, the return type needs to be an array.
@Relation(SubProtocol, (_) => [_.count])
sub_: SubProtocol
}
Even thought it's possible to use the @Relation()
decorator without
parameters you shouldn't do it yourself. This will be automatically done
with the help of Condition decorators.
@Relation
property decorator defines the type of the decorated property. This can be either: