2023-11-16 15:17:17 +03:00
|
|
|
import { DefaultPubsubTopic } from "@waku/interfaces";
|
2022-12-05 17:07:03 +11:00
|
|
|
import type {
|
|
|
|
|
IDecodedMessage,
|
|
|
|
|
IDecoder,
|
2023-08-16 20:18:13 +05:30
|
|
|
IProtoMessage
|
2022-12-05 17:07:03 +11:00
|
|
|
} from "@waku/interfaces";
|
2022-12-21 00:48:16 +11:00
|
|
|
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
|
2022-09-19 16:20:33 +10:00
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
export class TopicOnlyMessage implements IDecodedMessage {
|
2023-02-24 23:22:04 +11:00
|
|
|
public payload: Uint8Array = new Uint8Array();
|
2022-09-30 12:50:43 +10:00
|
|
|
public rateLimitProof: undefined;
|
|
|
|
|
public timestamp: undefined;
|
2023-03-10 14:41:07 +11:00
|
|
|
public meta: undefined;
|
2022-11-16 11:00:43 +11:00
|
|
|
public ephemeral: undefined;
|
2022-09-30 12:50:43 +10:00
|
|
|
|
2024-07-19 15:58:17 +05:30
|
|
|
public constructor(
|
2023-10-16 12:52:32 +05:30
|
|
|
public pubsubTopic: string,
|
2023-08-16 20:18:13 +05:30
|
|
|
private proto: ProtoTopicOnlyMessage
|
2023-03-10 16:43:21 +11:00
|
|
|
) {}
|
2022-09-19 16:20:33 +10:00
|
|
|
|
2024-07-19 15:58:17 +05:30
|
|
|
public get contentTopic(): string {
|
2023-02-24 23:22:04 +11:00
|
|
|
return this.proto.contentTopic;
|
2022-09-19 16:20:33 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 17:07:03 +11:00
|
|
|
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
2024-07-19 15:58:17 +05:30
|
|
|
public pubsubTopic = DefaultPubsubTopic;
|
2022-09-19 16:20:33 +10:00
|
|
|
public contentTopic = "";
|
|
|
|
|
|
2024-07-19 15:58:17 +05:30
|
|
|
public fromWireToProtoObj(
|
|
|
|
|
bytes: Uint8Array
|
|
|
|
|
): Promise<IProtoMessage | undefined> {
|
2022-12-21 00:48:16 +11:00
|
|
|
const protoMessage = ProtoTopicOnlyMessage.decode(bytes);
|
2022-09-30 12:50:43 +10:00
|
|
|
return Promise.resolve({
|
|
|
|
|
contentTopic: protoMessage.contentTopic,
|
2023-02-24 23:22:04 +11:00
|
|
|
payload: new Uint8Array(),
|
2022-09-30 12:50:43 +10:00
|
|
|
rateLimitProof: undefined,
|
|
|
|
|
timestamp: undefined,
|
2023-03-10 14:41:07 +11:00
|
|
|
meta: undefined,
|
2022-09-30 12:50:43 +10:00
|
|
|
version: undefined,
|
2023-08-16 20:18:13 +05:30
|
|
|
ephemeral: undefined
|
2022-09-30 12:50:43 +10:00
|
|
|
});
|
2022-09-19 16:20:33 +10:00
|
|
|
}
|
|
|
|
|
|
2024-07-19 15:58:17 +05:30
|
|
|
public async fromProtoObj(
|
2023-10-16 12:52:32 +05:30
|
|
|
pubsubTopic: string,
|
2023-08-16 20:18:13 +05:30
|
|
|
proto: IProtoMessage
|
2022-09-30 12:55:25 +10:00
|
|
|
): Promise<TopicOnlyMessage | undefined> {
|
2023-10-16 12:52:32 +05:30
|
|
|
return new TopicOnlyMessage(pubsubTopic, proto);
|
2022-09-19 16:20:33 +10:00
|
|
|
}
|
|
|
|
|
}
|