UNPKG

@libp2p/record

Version:
49 lines 1.56 kB
/** * @packageDocumentation * * This is an implementation of the [routing record format](https://github.com/libp2p/specs/blob/b9efe152c29f93f7a87931c14d78ae11e7924d5a/kad-dht/README.md?plain=1#L408-L425) used by libp2p to store data in the datastore passed to the libp2p constructor. * * @example Deserialization * * ```TypeScript * import { Libp2pRecord } from '@libp2p/record' * * const buf = Uint8Array.from([0, 1, 2, 3]) * const record = Libp2pRecord.deserialize(buf) * ``` * * @example Serialization * * ```TypeScript * import { Libp2pRecord } from '@libp2p/record' * * const key = Uint8Array.from([0, 1, 2, 3]) * const value = Uint8Array.from([0, 1, 2, 3]) * const timeReceived = new Date() * * const record = new Libp2pRecord(key, value, timeReceived) * const buf = record.serialize() * ``` */ import { Record } from './record.js'; import type { Uint8ArrayList } from 'uint8arraylist'; export declare class Libp2pRecord { key: Uint8Array; value: Uint8Array; timeReceived: Date; constructor(key: Uint8Array, value: Uint8Array, timeReceived: Date); serialize(): Uint8Array; /** * Return the object format ready to be given to the protobuf library. */ prepareSerialize(): Record; /** * Decode a protobuf encoded record */ static deserialize(raw: Uint8Array | Uint8ArrayList): Libp2pRecord; /** * Create a record from the raw object returned from the protobuf library */ static fromDeserialized(obj: Record): Libp2pRecord; } //# sourceMappingURL=index.d.ts.map