mirror of https://github.com/waku-org/js-waku.git
Extract `getPayloadSize` logic
This commit is contained in:
parent
95485f0a69
commit
33f52ef56d
|
@ -94,7 +94,7 @@ export function clearDecode(
|
||||||
const sizeOfPayloadSizeField = getSizeOfPayloadSizeField(message);
|
const sizeOfPayloadSizeField = getSizeOfPayloadSizeField(message);
|
||||||
if (sizeOfPayloadSizeField === 0) return;
|
if (sizeOfPayloadSizeField === 0) return;
|
||||||
|
|
||||||
const payloadSize = buf.readUIntLE(start, sizeOfPayloadSizeField);
|
const payloadSize = getPayloadSize(message, sizeOfPayloadSizeField);
|
||||||
start += sizeOfPayloadSizeField;
|
start += sizeOfPayloadSizeField;
|
||||||
const payload = buf.slice(start, start + payloadSize);
|
const payload = buf.slice(start, start + payloadSize);
|
||||||
|
|
||||||
|
@ -114,6 +114,14 @@ function getSizeOfPayloadSizeField(message: Uint8Array): number {
|
||||||
return messageDataView.getUint8(0) & FlagMask;
|
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/).
|
* 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].
|
* The data MUST be flags | payload-length | payload | [signature].
|
||||||
|
|
Loading…
Reference in New Issue