From 7be8515ad87d062bbc9db20fc3134ed06b1286a9 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 3 Aug 2022 11:20:16 +0100 Subject: [PATCH] deps: update deps to support no-copy operations (#55) --- package.json | 7 ++++--- src/index.ts | 3 ++- src/record.ts | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e14f039..0919d7d 100644 --- a/package.json +++ b/package.json @@ -169,12 +169,13 @@ "@libp2p/interface-dht": "^1.0.0", "err-code": "^3.0.1", "multiformats": "^9.4.5", - "protons-runtime": "^1.0.2", + "protons-runtime": "^2.0.2", + "uint8arraylist": "^2.1.1", "uint8arrays": "^3.0.0" }, "devDependencies": { - "@libp2p/crypto": "^0.22.10", + "@libp2p/crypto": "^1.0.2", "aegir": "^37.0.13", - "protons": "^3.0.2" + "protons": "^4.0.1" } } diff --git a/src/index.ts b/src/index.ts index 6503c5d..db154db 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import type { Uint8ArrayList } from 'uint8arraylist' import { Record } from './record.js' @@ -40,7 +41,7 @@ export class Libp2pRecord { /** * Decode a protobuf encoded record */ - static deserialize (raw: Uint8Array) { + static deserialize (raw: Uint8Array | Uint8ArrayList) { const rec = Record.decode(raw) return new Libp2pRecord(rec.key, rec.value, new Date(rec.timeReceived)) diff --git a/src/record.ts b/src/record.ts index f2ed6cb..8e84d3c 100644 --- a/src/record.ts +++ b/src/record.ts @@ -3,6 +3,7 @@ import { encodeMessage, decodeMessage, message, bytes, string } from 'protons-runtime' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Record { key: Uint8Array @@ -19,11 +20,11 @@ export namespace Record { }) } - export const encode = (obj: Record): Uint8Array => { + export const encode = (obj: Record): Uint8ArrayList => { return encodeMessage(obj, Record.codec()) } - export const decode = (buf: Uint8Array): Record => { + export const decode = (buf: Uint8Array | Uint8ArrayList): Record => { return decodeMessage(buf, Record.codec()) } }