mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-26 20:30:07 +00:00
feat: remove V0 suffix from Decoder/Encoder
This commit is contained in:
parent
e0c738c092
commit
0f5bef78d1
@ -1,7 +1,7 @@
|
|||||||
import type {
|
import type {
|
||||||
DecodedMessage,
|
DecodedMessage as IDecodedMessage,
|
||||||
Decoder,
|
Decoder as IDecoder,
|
||||||
Encoder,
|
Encoder as IEncoder,
|
||||||
Message,
|
Message,
|
||||||
ProtoMessage,
|
ProtoMessage,
|
||||||
RateLimitProof,
|
RateLimitProof,
|
||||||
@ -16,7 +16,7 @@ const OneMillion = BigInt(1_000_000);
|
|||||||
export const Version = 0;
|
export const Version = 0;
|
||||||
export { proto };
|
export { proto };
|
||||||
|
|
||||||
export class MessageV0 implements DecodedMessage {
|
export class DecodedMessage implements IDecodedMessage {
|
||||||
constructor(protected proto: proto.WakuMessage) {}
|
constructor(protected proto: proto.WakuMessage) {}
|
||||||
|
|
||||||
get _rawPayload(): Uint8Array | undefined {
|
get _rawPayload(): Uint8Array | undefined {
|
||||||
@ -71,7 +71,7 @@ export class MessageV0 implements DecodedMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EncoderV0 implements Encoder {
|
class Encoder implements IEncoder {
|
||||||
constructor(public contentTopic: string, public ephemeral: boolean = false) {}
|
constructor(public contentTopic: string, public ephemeral: boolean = false) {}
|
||||||
|
|
||||||
async toWire(message: Partial<Message>): Promise<Uint8Array> {
|
async toWire(message: Partial<Message>): Promise<Uint8Array> {
|
||||||
@ -92,7 +92,14 @@ export class EncoderV0 implements Encoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DecoderV0 implements Decoder<MessageV0> {
|
export function createEncoder(
|
||||||
|
contentTopic: string,
|
||||||
|
ephemeral = false
|
||||||
|
): Encoder {
|
||||||
|
return new Encoder(contentTopic, ephemeral);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Decoder implements IDecoder<DecodedMessage> {
|
||||||
constructor(public contentTopic: string, public ephemeral: boolean = false) {}
|
constructor(public contentTopic: string, public ephemeral: boolean = false) {}
|
||||||
|
|
||||||
fromWireToProtoObj(bytes: Uint8Array): Promise<ProtoMessage | undefined> {
|
fromWireToProtoObj(bytes: Uint8Array): Promise<ProtoMessage | undefined> {
|
||||||
@ -108,7 +115,7 @@ export class DecoderV0 implements Decoder<MessageV0> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async fromProtoObj(proto: ProtoMessage): Promise<MessageV0 | undefined> {
|
async fromProtoObj(proto: ProtoMessage): Promise<DecodedMessage | undefined> {
|
||||||
// https://github.com/status-im/js-waku/issues/921
|
// https://github.com/status-im/js-waku/issues/921
|
||||||
if (proto.version === undefined) {
|
if (proto.version === undefined) {
|
||||||
proto.version = 0;
|
proto.version = 0;
|
||||||
@ -124,6 +131,13 @@ export class DecoderV0 implements Decoder<MessageV0> {
|
|||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MessageV0(proto);
|
return new DecodedMessage(proto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createDecoder(
|
||||||
|
contentTopic: string,
|
||||||
|
ephemeral = false
|
||||||
|
): Encoder {
|
||||||
|
return new Decoder(contentTopic, ephemeral);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user