summaryrefslogtreecommitdiff
path: root/node_modules/capnp-ts/src/serialization/pointers/text-list.ts
blob: 0c2c8fd797c2f4edeb329e4b8f65c6135231fb78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * @author jdiaz5513
 */

import initTrace from "debug";

import { ListElementSize } from "../list-element-size";
import { _ListCtor, List } from "./list";
import { Text } from "./text";
import { getContent } from "./pointer";

const trace = initTrace("capnp:list:composite");
trace("load");

export class TextList extends List<string> {
  static readonly _capnp: _ListCtor = {
    displayName: "List<Text>" as string,
    size: ListElementSize.POINTER
  };

  get(index: number): string {
    const c = getContent(this);

    c.byteOffset += index * 8;

    return Text.fromPointer(c).get(0);
  }

  set(index: number, value: string): void {
    const c = getContent(this);

    c.byteOffset += index * 8;

    Text.fromPointer(c).set(0, value);
  }

  toString(): string {
    return `Text_${super.toString()}`;
  }
}