Skip to content

Latest commit

 

History

History
161 lines (102 loc) · 4.35 KB

Component.md

File metadata and controls

161 lines (102 loc) · 4.35 KB

Class: Component

Types

<BaseComponentProps>

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.

<ComponentProps>

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.

Constructors

new Component(props)

Creates a versioned component. This constructor is used internally. You shouldn't create any instances of this base class.

⚠️ You shouldn't create any instances of this base class. Use any of its derived classes instead.


Component.fromBinary(reader, version)

Reads the binary string data and returns an instantiated component.

  • reader BinaryReader The BinaryReader instance containing the entity binary data.
  • version <number> The version of the component for interpreting the binary data.

⚠️ You shouldn't create any instances of this base class. Use any of its derived classes instead.

Properties

Note that the following properties are sorted in order of appearance when decoding component binary data.

hash

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;

name

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;

version

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`

Methods

toBinary(version?)

Returns a BinaryString representation of the component.

  • version (optional, default this.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);

write(writer, version?)

Writes a BinaryString representation of the component to the given BinaryWriter, including the component hash and data length.

  • writer <BinaryWriter> The BinaryWriter instance in which to store the binary data.
  • version (optional, default this.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);