A portion of the configuration object to pass to the Component
constructor. These properties are only present on the base Component
class constructor and are not used in derived classes.
type BaseComponentProps = {
hash: number;
name: string;
};
hash
<number>
The hash of the component.name
<string>
The name of the component.
A portion of the configuration object to pass to the Component
constructor. These properties are also used in all derived class constructors.
type ComponentProps = {
version: number;
};
version
<number>
The version of the component, which controls its data shape and (de)serialisation sequence.
Creates a versioned component. This constructor is used internally. You shouldn't create any instances of this base class.
props
<ComponentProps & BaseComponentProps>
Configuration of the component to create.- Returns:
<Component>
Reads the binary string data and returns an instantiated component.
reader
BinaryReader
TheBinaryReader
instance containing the entity binary data.version
<number>
The version of the component for interpreting the binary data.
Note that the following properties are sorted in order of appearance when decoding component binary data.
The hash of the component.
<number>
The hash of the component.
import { DerivedComponent } from 'att-string-transcoder';
const componentVersion = 1;
const component = new DerivedComponent({ version: componentVersion });
const hash = component.hash;
The name of the component.
<string>
The name of the component.
import { DerivedComponent } from 'att-string-transcoder';
const componentVersion = 1;
const component = new DerivedComponent({ version: componentVersion });
const name = component.name;
The version of the component. This controls the shape of the component data and its (de)serialisation sequence when reading or writing binary data.
<number>
The version of the component.
import { DerivedComponent } from 'att-string-transcoder';
const componentVersion = 1;
const component = new DerivedComponent({ version: componentVersion });
const version = component.version;
// `version` is `1`
Returns a BinaryString
representation of the component.
version
(optional, defaultthis.version
)<number>
The version of the component, which controls its serialisation sequence.- Returns:
<BinaryString>
import { DerivedComponent } from 'att-string-transcoder';
const componentVersion = 1;
const component = new DerivedComponent({ version: componentVersion });
const binaryString = component.toBinary(componentVersion);
Writes a BinaryString
representation of the component to the given BinaryWriter
, including the component hash and data length.
writer
<BinaryWriter>
TheBinaryWriter
instance in which to store the binary data.version
(optional, defaultthis.version
)<number>
The version of the component, which controls its serialisation sequence.- Returns:
<void>
import { BinaryWriter, DerivedComponent } from 'att-string-transcoder';
const writer = new BinaryWriter();
const componentVersion = 1;
const component = new DerivedComponent({ version: componentVersion });
component.write(writer, componentVersion);