mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-03 14:23:12 +00:00
Extract getPayloadSize logic
This commit is contained in:
parent
95485f0a69
commit
33f52ef56d
@ -94,7 +94,7 @@ export function clearDecode(
|
||||
const sizeOfPayloadSizeField = getSizeOfPayloadSizeField(message);
|
||||
if (sizeOfPayloadSizeField === 0) return;
|
||||
|
||||
const payloadSize = buf.readUIntLE(start, sizeOfPayloadSizeField);
|
||||
const payloadSize = getPayloadSize(message, sizeOfPayloadSizeField);
|
||||
start += sizeOfPayloadSizeField;
|
||||
const payload = buf.slice(start, start + payloadSize);
|
||||
|
||||
@ -114,6 +114,14 @@ function getSizeOfPayloadSizeField(message: Uint8Array): number {
|
||||
return messageDataView.getUint8(0) & FlagMask;
|
||||
}
|
||||
|
||||
function getPayloadSize(
|
||||
message: Uint8Array,
|
||||
sizeOfPayloadSizeField: number
|
||||
): number {
|
||||
const buf = Buffer.from(message);
|
||||
return buf.readUIntLE(1, sizeOfPayloadSizeField);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proceed with Asymmetric encryption of the data as per [26/WAKU-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
||||
* The data MUST be flags | payload-length | payload | [signature].
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user