js-waku/packages/relay/src/topic_only_message.ts
Danish Arora 0f7d63ef93
feat: Logger with log levels (#1672)
* 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
2023-10-20 16:36:47 +05:30

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);
}
}