mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-09 01:03:11 +00:00
* setup a custom Logger with log level support * refactor codebase for to use new Logger with log levels * disallow usage of `debug` directly / only allow usage in/through custom Logger * remove `debug` from logger
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { DefaultPubSubTopic } from "@waku/core";
|
|
import type {
|
|
IDecodedMessage,
|
|
IDecoder,
|
|
IProtoMessage
|
|
} from "@waku/interfaces";
|
|
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
|
|
|
|
export class TopicOnlyMessage implements IDecodedMessage {
|
|
public payload: Uint8Array = new Uint8Array();
|
|
public rateLimitProof: undefined;
|
|
public timestamp: undefined;
|
|
public meta: undefined;
|
|
public ephemeral: undefined;
|
|
|
|
constructor(
|
|
public pubsubTopic: string,
|
|
private proto: ProtoTopicOnlyMessage
|
|
) {}
|
|
|
|
get contentTopic(): string {
|
|
return this.proto.contentTopic;
|
|
}
|
|
}
|
|
|
|
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
|
pubsubTopic = DefaultPubSubTopic;
|
|
public contentTopic = "";
|
|
|
|
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
|
const protoMessage = ProtoTopicOnlyMessage.decode(bytes);
|
|
return Promise.resolve({
|
|
contentTopic: protoMessage.contentTopic,
|
|
payload: new Uint8Array(),
|
|
rateLimitProof: undefined,
|
|
timestamp: undefined,
|
|
meta: undefined,
|
|
version: undefined,
|
|
ephemeral: undefined
|
|
});
|
|
}
|
|
|
|
async fromProtoObj(
|
|
pubsubTopic: string,
|
|
proto: IProtoMessage
|
|
): Promise<TopicOnlyMessage | undefined> {
|
|
return new TopicOnlyMessage(pubsubTopic, proto);
|
|
}
|
|
}
|