chore: update filter.proto

Ref: https://github.com/vacp2p/waku
This commit is contained in:
fryorcraken.eth 2023-02-24 15:57:50 +11:00
parent 31740e7a3d
commit 5f0e8b72f5
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 39 additions and 30 deletions

View File

@ -9,7 +9,7 @@ export type ContentFilter = {
* FilterRPC represents a message conforming to the Waku Filter protocol * FilterRPC represents a message conforming to the Waku Filter protocol
*/ */
export class FilterRPC { export class FilterRPC {
public constructor(public proto: proto.FilterRPC) {} public constructor(public proto: proto.FilterRpc) {}
static createRequest( static createRequest(
topic: string, topic: string,
@ -34,7 +34,7 @@ export class FilterRPC {
* @returns FilterRPC * @returns FilterRPC
*/ */
static decode(bytes: Uint8Array): FilterRPC { static decode(bytes: Uint8Array): FilterRPC {
const res = proto.FilterRPC.decode(bytes); const res = proto.FilterRpc.decode(bytes);
return new FilterRPC(res); return new FilterRPC(res);
} }
@ -43,14 +43,14 @@ export class FilterRPC {
* @returns Uint8Array * @returns Uint8Array
*/ */
encode(): Uint8Array { encode(): Uint8Array {
return proto.FilterRPC.encode(this.proto); return proto.FilterRpc.encode(this.proto);
} }
get push(): proto.MessagePush | undefined { get push(): proto.MessagePush | undefined {
return this.proto.push; return this.proto.push;
} }
get requestId(): string | undefined { get requestId(): string {
return this.proto.requestId; return this.proto.requestId;
} }
} }

View File

@ -1,23 +1,26 @@
// 12/WAKU2-FILTER rfc: https://rfc.vac.dev/spec/12/
// Protocol identifier: /vac/waku/filter/2.0.0-beta1
syntax = "proto3"; syntax = "proto3";
import "message.proto"; import "message.proto";
message FilterRequest { message FilterRequest {
optional bool subscribe = 1;
optional string topic = 2;
repeated ContentFilter content_filters = 3;
message ContentFilter { message ContentFilter {
optional string content_topic = 1; string content_topic = 1;
} }
bool subscribe = 1;
string topic = 2;
repeated ContentFilter content_filters = 3;
} }
message MessagePush { message MessagePush {
repeated WakuMessage messages = 1; repeated WakuMessage messages = 1;
} }
message FilterRPC { message FilterRpc {
optional string request_id = 1; string request_id = 1;
optional FilterRequest request = 2; optional FilterRequest request = 2;
optional MessagePush push = 3; optional MessagePush push = 3;
} }

View File

@ -9,14 +9,14 @@ import type { Codec } from "protons-runtime";
import type { Uint8ArrayList } from "uint8arraylist"; import type { Uint8ArrayList } from "uint8arraylist";
export interface FilterRequest { export interface FilterRequest {
subscribe?: boolean; subscribe: boolean;
topic?: string; topic: string;
contentFilters: FilterRequest.ContentFilter[]; contentFilters: FilterRequest.ContentFilter[];
} }
export namespace FilterRequest { export namespace FilterRequest {
export interface ContentFilter { export interface ContentFilter {
contentTopic?: string; contentTopic: string;
} }
export namespace ContentFilter { export namespace ContentFilter {
@ -30,7 +30,7 @@ export namespace FilterRequest {
w.fork(); w.fork();
} }
if (obj.contentTopic != null) { if (obj.contentTopic != null && obj.contentTopic !== "") {
w.uint32(10); w.uint32(10);
w.string(obj.contentTopic); w.string(obj.contentTopic);
} }
@ -40,7 +40,9 @@ export namespace FilterRequest {
} }
}, },
(reader, length) => { (reader, length) => {
const obj: any = {}; const obj: any = {
contentTopic: "",
};
const end = length == null ? reader.len : reader.pos + length; const end = length == null ? reader.len : reader.pos + length;
@ -84,12 +86,12 @@ export namespace FilterRequest {
w.fork(); w.fork();
} }
if (obj.subscribe != null) { if (obj.subscribe != null && obj.subscribe !== false) {
w.uint32(8); w.uint32(8);
w.bool(obj.subscribe); w.bool(obj.subscribe);
} }
if (obj.topic != null) { if (obj.topic != null && obj.topic !== "") {
w.uint32(18); w.uint32(18);
w.string(obj.topic); w.string(obj.topic);
} }
@ -107,6 +109,8 @@ export namespace FilterRequest {
}, },
(reader, length) => { (reader, length) => {
const obj: any = { const obj: any = {
subscribe: false,
topic: "",
contentFilters: [], contentFilters: [],
}; };
@ -218,24 +222,24 @@ export namespace MessagePush {
}; };
} }
export interface FilterRPC { export interface FilterRpc {
requestId?: string; requestId: string;
request?: FilterRequest; request?: FilterRequest;
push?: MessagePush; push?: MessagePush;
} }
export namespace FilterRPC { export namespace FilterRpc {
let _codec: Codec<FilterRPC>; let _codec: Codec<FilterRpc>;
export const codec = (): Codec<FilterRPC> => { export const codec = (): Codec<FilterRpc> => {
if (_codec == null) { if (_codec == null) {
_codec = message<FilterRPC>( _codec = message<FilterRpc>(
(obj, w, opts = {}) => { (obj, w, opts = {}) => {
if (opts.lengthDelimited !== false) { if (opts.lengthDelimited !== false) {
w.fork(); w.fork();
} }
if (obj.requestId != null) { if (obj.requestId != null && obj.requestId !== "") {
w.uint32(10); w.uint32(10);
w.string(obj.requestId); w.string(obj.requestId);
} }
@ -255,7 +259,9 @@ export namespace FilterRPC {
} }
}, },
(reader, length) => { (reader, length) => {
const obj: any = {}; const obj: any = {
requestId: "",
};
const end = length == null ? reader.len : reader.pos + length; const end = length == null ? reader.len : reader.pos + length;
@ -289,12 +295,12 @@ export namespace FilterRPC {
return _codec; return _codec;
}; };
export const encode = (obj: Partial<FilterRPC>): Uint8Array => { export const encode = (obj: Partial<FilterRpc>): Uint8Array => {
return encodeMessage(obj, FilterRPC.codec()); return encodeMessage(obj, FilterRpc.codec());
}; };
export const decode = (buf: Uint8Array | Uint8ArrayList): FilterRPC => { export const decode = (buf: Uint8Array | Uint8ArrayList): FilterRpc => {
return decodeMessage(buf, FilterRPC.codec()); return decodeMessage(buf, FilterRpc.codec());
}; };
} }