Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ProtoMap<TKey, TValue>

Type Parameters

  • TKey

  • TValue

Hierarchy

  • ProtoMap

Index

Constructors

  • new ProtoMap<TKey, TValue>(contractId: Uint8Array, spaceId: number, keyDecoder: ((reader: Reader, length: number) => TKey), keyEncoder: ((message: TKey, writer: Writer) => void), valueDecoder: ((reader: Reader, length: number) => TValue), valueEncoder: ((message: TValue, writer: Writer) => void), defaultValue?: null | (() => null | TValue), system?: bool): ProtoMap<TKey, TValue>
  • Initialize a Space object with TKey (a protobuf type) the type of the keys and TValue the type of the values

    example
    const contractId = Base58.decode('1DQzuCcTKacbs9GGScFTU1Hc8BsyARTPqe');
    const spaceId = 1;
    const Objects = new Space.SpaceProtoKey<String, test_object>(contractId, spaceId, test_key.encode, test_object.decode, test_object.encode);

    Type Parameters

    • TKey

    • TValue

    Parameters

    • contractId: Uint8Array

      the id of the contract

    • spaceId: number

      the id of the space

    • keyDecoder: ((reader: Reader, length: number) => TKey)
        • (reader: Reader, length: number): TKey
        • Parameters

          • reader: Reader
          • length: number

          Returns TKey

    • keyEncoder: ((message: TKey, writer: Writer) => void)

      the protobuf encoder for the keys

        • (message: TKey, writer: Writer): void
        • Parameters

          • message: TKey
          • writer: Writer

          Returns void

    • valueDecoder: ((reader: Reader, length: number) => TValue)

      the protobuf decoder for the values

        • (reader: Reader, length: number): TValue
        • Parameters

          • reader: Reader
          • length: number

          Returns TValue

    • valueEncoder: ((message: TValue, writer: Writer) => void)

      the protobuf encoder for the values

        • (message: TValue, writer: Writer): void
        • Parameters

          • message: TValue
          • writer: Writer

          Returns void

    • defaultValue: null | (() => null | TValue) = null
    • system: bool = false

      is system space

    Returns ProtoMap<TKey, TValue>

Properties

keyDecoder: ((reader: Reader, length: number) => TKey)

Type declaration

    • (reader: Reader, length: number): TKey
    • Parameters

      • reader: Reader
      • length: number

      Returns TKey

keyEncoder: ((message: TKey, writer: Writer) => void)

Type declaration

    • (message: TKey, writer: Writer): void
    • Parameters

      • message: TKey
      • writer: Writer

      Returns void

map: Map<Uint8Array, TValue>

Methods

  • get(key: TKey): null | TValue
  • Get an object from the space

    example
    const obj = Objects.get(new test_key(1));

    if (obj != null) {
    ...
    }

    Parameters

    • key: TKey

      key to get

    Returns null | TValue

    the object if exists, null otherwise

  • Get many objects from the space

    example
    const objs = Objects.getManyObj(new test_key(1), 10, Space.Direction.Descending);

    for (let index = 0; index < objs.length; index++) {
    const obj = objs[index];
    }

    Parameters

    • offsetKey: TKey

      key used as the offset

    • limit: number = i32.MAX_VALUE

      number of objects to return

    • direction: Direction = Direction.Ascending

      direction of the get, Ascending or Descending

    Returns ProtoDatabaseObject<TValue>[]

    an array with the objects retrieved

  • getManyObjKeys(offsetKey: TKey, limit?: number, direction?: Direction): TKey[]
  • Get many keys from the space

    example
    const keys = Objects.getManyObjKeys(new test_key(1), 10, Space.Direction.Descending);

    for (let index = 0; index < keys.length; index++) {
    const key = keys[index];
    }

    Parameters

    • offsetKey: TKey

      key used as the offset

    • limit: number = i32.MAX_VALUE

      number of keys to return

    • direction: Direction = Direction.Ascending

      direction of the get, Ascending or Descending

    Returns TKey[]

    an array with the keys retrieved

  • getManyObjValues(offsetKey: TKey, limit?: number, direction?: Direction): TValue[]
  • Get many values from the space

    example
    const values = Objects.getManyObjValues(new test_key(1), 10, Space.Direction.Descending);

    for (let index = 0; index < values.length; index++) {
    const value = values[index];
    }

    Parameters

    • offsetKey: TKey

      key used as the offset

    • limit: number = i32.MAX_VALUE

      number of objects to return

    • direction: Direction = Direction.Ascending

      direction of the get, Ascending or Descending

    Returns TValue[]

    an array with the objects retrieved

  • Get the next object from the space

    example
    const obj = Objects.getNext(new test_key(1));

    if (obj != null) {
    const key = obj.key;
    const val = obj.value;
    }

    Parameters

    • key: TKey

      key to get next

    Returns null | ProtoDatabaseObject<TValue>

    a System.ProtoDatabaseObject if exists, null otherwise

  • Get the previous object from the space

    example
    const obj = Objects.getPrev(new test_key(1));

    if (obj != null) {
    const key = obj.key;
    const val = obj.value;
    }

    Parameters

    • key: TKey

      key to get previous

    Returns null | ProtoDatabaseObject<TValue>

    a System.ProtoDatabaseObject if exists, null otherwise

  • has(key: TKey): boolean
  • Check if key exists in the space

    example
    const exists = Objects.has(new test_key(1));

    if (exists) {
    ...
    }

    Parameters

    • key: TKey

      key to check

    Returns boolean

  • put(key: TKey, object: TValue): void
  • Put an object in the space

    example
    const nbBytesWritten = Objects.put(new test_key(1), new test_object(42));

    System.log(nbBytesWritten.toString());

    Parameters

    • key: TKey

      key of the object

    • object: TValue

    Returns void

    number of bytes that were written in the space

  • remove(key: TKey): void
  • Remove an object from the space

    example
    Objects.remove(new test_key(1));
    

    Parameters

    • key: TKey

      key of the object

    Returns void

Generated using TypeDoc