mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-27 12:45:21 +00:00
Remove Buffer from getPayloadSize
This commit is contained in:
parent
33f52ef56d
commit
bd9d592fda
@ -118,14 +118,23 @@ function getPayloadSize(
|
|||||||
message: Uint8Array,
|
message: Uint8Array,
|
||||||
sizeOfPayloadSizeField: number
|
sizeOfPayloadSizeField: number
|
||||||
): number {
|
): number {
|
||||||
const buf = Buffer.from(message);
|
let payloadSizeBytes = message.slice(1, 1 + sizeOfPayloadSizeField);
|
||||||
return buf.readUIntLE(1, sizeOfPayloadSizeField);
|
// int 32 == 4 bytes
|
||||||
|
if (sizeOfPayloadSizeField < 4) {
|
||||||
|
// If less than 4 bytes pad right (Little Endian).
|
||||||
|
payloadSizeBytes = concat(
|
||||||
|
[payloadSizeBytes, new Uint8Array(4 - sizeOfPayloadSizeField)],
|
||||||
|
4
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const payloadSizeDataView = new DataView(payloadSizeBytes.buffer);
|
||||||
|
return payloadSizeDataView.getInt32(0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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].
|
||||||
* The returned result can be set to `WakuMessage.payload`.
|
* The returned result can be set to `WakuMessage.payload`.
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user