mirror of https://github.com/waku-org/js-waku.git
chore: update light_push.proto
Ref: https://github.com/vacp2p/waku/blob/main/waku/lightpush/v2beta1/lightpush.proto
This commit is contained in:
parent
d6184fb41a
commit
3e93e8f49e
|
@ -3,7 +3,7 @@ import type { Uint8ArrayList } from "uint8arraylist";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
|
|
||||||
export class PushRPC {
|
export class PushRPC {
|
||||||
public constructor(public proto: proto.PushRPC) {}
|
public constructor(public proto: proto.PushRpc) {}
|
||||||
|
|
||||||
static createRequest(
|
static createRequest(
|
||||||
message: proto.WakuMessage,
|
message: proto.WakuMessage,
|
||||||
|
@ -13,19 +13,19 @@ export class PushRPC {
|
||||||
requestId: uuid(),
|
requestId: uuid(),
|
||||||
request: {
|
request: {
|
||||||
message: message,
|
message: message,
|
||||||
pubSubTopic: pubSubTopic,
|
pubsubTopic: pubSubTopic,
|
||||||
},
|
},
|
||||||
response: undefined,
|
response: undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static decode(bytes: Uint8ArrayList): PushRPC {
|
static decode(bytes: Uint8ArrayList): PushRPC {
|
||||||
const res = proto.PushRPC.decode(bytes);
|
const res = proto.PushRpc.decode(bytes);
|
||||||
return new PushRPC(res);
|
return new PushRPC(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
encode(): Uint8Array {
|
encode(): Uint8Array {
|
||||||
return proto.PushRPC.encode(this.proto);
|
return proto.PushRpc.encode(this.proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
get query(): proto.PushRequest | undefined {
|
get query(): proto.PushRequest | undefined {
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
|
// 19/WAKU2-LIGHTPUSH rfc: https://rfc.vac.dev/spec/19/
|
||||||
|
// Protocol identifier: /vac/waku/lightpush/2.0.0-beta1
|
||||||
|
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
import "message.proto";
|
import "message.proto";
|
||||||
|
|
||||||
message PushRequest {
|
message PushRequest {
|
||||||
optional string pub_sub_topic = 1;
|
string pubsub_topic = 1;
|
||||||
optional WakuMessage message = 2;
|
WakuMessage message = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PushResponse {
|
message PushResponse {
|
||||||
optional bool is_success = 1;
|
bool is_success = 1;
|
||||||
optional string info = 2;
|
optional string info = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PushRPC {
|
message PushRpc {
|
||||||
optional string request_id = 1;
|
string request_id = 1;
|
||||||
optional PushRequest request = 2;
|
optional PushRequest request = 2;
|
||||||
optional PushResponse response = 3;
|
optional PushResponse response = 3;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import type { Codec } from "protons-runtime";
|
||||||
import type { Uint8ArrayList } from "uint8arraylist";
|
import type { Uint8ArrayList } from "uint8arraylist";
|
||||||
|
|
||||||
export interface PushRequest {
|
export interface PushRequest {
|
||||||
pubSubTopic?: string;
|
pubsubTopic: string;
|
||||||
message?: WakuMessage;
|
message?: WakuMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ export namespace PushRequest {
|
||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.pubSubTopic != null) {
|
if (obj.pubsubTopic != null && obj.pubsubTopic !== "") {
|
||||||
w.uint32(10);
|
w.uint32(10);
|
||||||
w.string(obj.pubSubTopic);
|
w.string(obj.pubsubTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.message != null) {
|
if (obj.message != null) {
|
||||||
|
@ -39,7 +39,9 @@ export namespace PushRequest {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
pubsubTopic: "",
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ export namespace PushRequest {
|
||||||
|
|
||||||
switch (tag >>> 3) {
|
switch (tag >>> 3) {
|
||||||
case 1:
|
case 1:
|
||||||
obj.pubSubTopic = reader.string();
|
obj.pubsubTopic = reader.string();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
obj.message = WakuMessage.codec().decode(
|
obj.message = WakuMessage.codec().decode(
|
||||||
|
@ -80,7 +82,7 @@ export namespace PushRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PushResponse {
|
export interface PushResponse {
|
||||||
isSuccess?: boolean;
|
isSuccess: boolean;
|
||||||
info?: string;
|
info?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +97,7 @@ export namespace PushResponse {
|
||||||
w.fork();
|
w.fork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.isSuccess != null) {
|
if (obj.isSuccess != null && obj.isSuccess !== false) {
|
||||||
w.uint32(8);
|
w.uint32(8);
|
||||||
w.bool(obj.isSuccess);
|
w.bool(obj.isSuccess);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +112,9 @@ export namespace PushResponse {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(reader, length) => {
|
(reader, length) => {
|
||||||
const obj: any = {};
|
const obj: any = {
|
||||||
|
isSuccess: false,
|
||||||
|
};
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length;
|
const end = length == null ? reader.len : reader.pos + length;
|
||||||
|
|
||||||
|
@ -147,24 +151,24 @@ export namespace PushResponse {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PushRPC {
|
export interface PushRpc {
|
||||||
requestId?: string;
|
requestId: string;
|
||||||
request?: PushRequest;
|
request?: PushRequest;
|
||||||
response?: PushResponse;
|
response?: PushResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace PushRPC {
|
export namespace PushRpc {
|
||||||
let _codec: Codec<PushRPC>;
|
let _codec: Codec<PushRpc>;
|
||||||
|
|
||||||
export const codec = (): Codec<PushRPC> => {
|
export const codec = (): Codec<PushRpc> => {
|
||||||
if (_codec == null) {
|
if (_codec == null) {
|
||||||
_codec = message<PushRPC>(
|
_codec = message<PushRpc>(
|
||||||
(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);
|
||||||
}
|
}
|
||||||
|
@ -184,7 +188,9 @@ export namespace PushRPC {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(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;
|
||||||
|
|
||||||
|
@ -221,12 +227,12 @@ export namespace PushRPC {
|
||||||
return _codec;
|
return _codec;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const encode = (obj: Partial<PushRPC>): Uint8Array => {
|
export const encode = (obj: Partial<PushRpc>): Uint8Array => {
|
||||||
return encodeMessage(obj, PushRPC.codec());
|
return encodeMessage(obj, PushRpc.codec());
|
||||||
};
|
};
|
||||||
|
|
||||||
export const decode = (buf: Uint8Array | Uint8ArrayList): PushRPC => {
|
export const decode = (buf: Uint8Array | Uint8ArrayList): PushRpc => {
|
||||||
return decodeMessage(buf, PushRPC.codec());
|
return decodeMessage(buf, PushRpc.codec());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue