mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-02-01 23:03:08 +00:00
40 lines
778 B
TypeScript
40 lines
778 B
TypeScript
export interface Waku2 {
|
|
relay: boolean;
|
|
store: boolean;
|
|
filter: boolean;
|
|
lightPush: boolean;
|
|
}
|
|
|
|
export function encodeWaku2(protocols: Waku2): number {
|
|
let byte = 0;
|
|
|
|
if (protocols.lightPush) byte += 1;
|
|
byte = byte << 1;
|
|
if (protocols.filter) byte += 1;
|
|
byte = byte << 1;
|
|
if (protocols.store) byte += 1;
|
|
byte = byte << 1;
|
|
if (protocols.relay) byte += 1;
|
|
|
|
return byte;
|
|
}
|
|
|
|
export function decodeWaku2(byte: number): Waku2 {
|
|
const waku2 = {
|
|
relay: false,
|
|
store: false,
|
|
filter: false,
|
|
lightPush: false,
|
|
};
|
|
|
|
if (byte % 2) waku2.relay = true;
|
|
byte = byte >> 1;
|
|
if (byte % 2) waku2.store = true;
|
|
byte = byte >> 1;
|
|
if (byte % 2) waku2.filter = true;
|
|
byte = byte >> 1;
|
|
if (byte % 2) waku2.lightPush = true;
|
|
|
|
return waku2;
|
|
}
|