mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-04 06:43:12 +00:00
Remove Proto suffix
Manage with namespace instead.
This commit is contained in:
parent
330caa2525
commit
3b7fc44419
@ -2,7 +2,7 @@ syntax = "proto3";
|
|||||||
|
|
||||||
package chat.v2;
|
package chat.v2;
|
||||||
|
|
||||||
message ChatMessageProto {
|
message ChatMessage {
|
||||||
uint64 timestamp = 1;
|
uint64 timestamp = 1;
|
||||||
string nick = 2;
|
string nick = 2;
|
||||||
bytes payload = 3;
|
bytes payload = 3;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Reader } from 'protobufjs/minimal';
|
import { Reader } from 'protobufjs/minimal';
|
||||||
|
|
||||||
import { ChatMessageProto } from '../../proto/chat/v2/chat_message';
|
import * as proto from '../../proto/chat/v2/chat_message';
|
||||||
|
|
||||||
// TODO: Move to waku library?
|
// TODO: Move to waku library?
|
||||||
export class ChatMessage {
|
export class ChatMessage {
|
||||||
@ -11,7 +11,7 @@ export class ChatMessage {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
static decode(bytes: Uint8Array): ChatMessage {
|
static decode(bytes: Uint8Array): ChatMessage {
|
||||||
const protoMsg = ChatMessageProto.decode(Reader.create(bytes));
|
const protoMsg = proto.ChatMessage.decode(Reader.create(bytes));
|
||||||
const timestamp = new Date(protoMsg.timestamp * 1000);
|
const timestamp = new Date(protoMsg.timestamp * 1000);
|
||||||
const message = protoMsg.payload
|
const message = protoMsg.payload
|
||||||
? Array.from(protoMsg.payload)
|
? Array.from(protoMsg.payload)
|
||||||
@ -27,7 +27,7 @@ export class ChatMessage {
|
|||||||
const timestamp = Math.floor(this.timestamp.valueOf() / 1000);
|
const timestamp = Math.floor(this.timestamp.valueOf() / 1000);
|
||||||
const payload = Buffer.from(this.message, 'utf-8');
|
const payload = Buffer.from(this.message, 'utf-8');
|
||||||
|
|
||||||
return ChatMessageProto.encode({
|
return proto.ChatMessage.encode({
|
||||||
timestamp,
|
timestamp,
|
||||||
nick: this.nick,
|
nick: this.nick,
|
||||||
payload,
|
payload,
|
||||||
|
|||||||
@ -4,17 +4,17 @@ import _m0 from 'protobufjs/minimal';
|
|||||||
|
|
||||||
export const protobufPackage = 'chat.v2';
|
export const protobufPackage = 'chat.v2';
|
||||||
|
|
||||||
export interface ChatMessageProto {
|
export interface ChatMessage {
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
nick: string;
|
nick: string;
|
||||||
payload: Uint8Array;
|
payload: Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseChatMessageProto: object = { timestamp: 0, nick: '' };
|
const baseChatMessage: object = { timestamp: 0, nick: '' };
|
||||||
|
|
||||||
export const ChatMessageProto = {
|
export const ChatMessage = {
|
||||||
encode(
|
encode(
|
||||||
message: ChatMessageProto,
|
message: ChatMessage,
|
||||||
writer: _m0.Writer = _m0.Writer.create()
|
writer: _m0.Writer = _m0.Writer.create()
|
||||||
): _m0.Writer {
|
): _m0.Writer {
|
||||||
if (message.timestamp !== 0) {
|
if (message.timestamp !== 0) {
|
||||||
@ -29,10 +29,10 @@ export const ChatMessageProto = {
|
|||||||
return writer;
|
return writer;
|
||||||
},
|
},
|
||||||
|
|
||||||
decode(input: _m0.Reader | Uint8Array, length?: number): ChatMessageProto {
|
decode(input: _m0.Reader | Uint8Array, length?: number): ChatMessage {
|
||||||
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
||||||
let end = length === undefined ? reader.len : reader.pos + length;
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
const message = { ...baseChatMessageProto } as ChatMessageProto;
|
const message = { ...baseChatMessage } as ChatMessage;
|
||||||
message.payload = new Uint8Array();
|
message.payload = new Uint8Array();
|
||||||
while (reader.pos < end) {
|
while (reader.pos < end) {
|
||||||
const tag = reader.uint32();
|
const tag = reader.uint32();
|
||||||
@ -54,8 +54,8 @@ export const ChatMessageProto = {
|
|||||||
return message;
|
return message;
|
||||||
},
|
},
|
||||||
|
|
||||||
fromJSON(object: any): ChatMessageProto {
|
fromJSON(object: any): ChatMessage {
|
||||||
const message = { ...baseChatMessageProto } as ChatMessageProto;
|
const message = { ...baseChatMessage } as ChatMessage;
|
||||||
message.payload = new Uint8Array();
|
message.payload = new Uint8Array();
|
||||||
if (object.timestamp !== undefined && object.timestamp !== null) {
|
if (object.timestamp !== undefined && object.timestamp !== null) {
|
||||||
message.timestamp = Number(object.timestamp);
|
message.timestamp = Number(object.timestamp);
|
||||||
@ -73,7 +73,7 @@ export const ChatMessageProto = {
|
|||||||
return message;
|
return message;
|
||||||
},
|
},
|
||||||
|
|
||||||
toJSON(message: ChatMessageProto): unknown {
|
toJSON(message: ChatMessage): unknown {
|
||||||
const obj: any = {};
|
const obj: any = {};
|
||||||
message.timestamp !== undefined && (obj.timestamp = message.timestamp);
|
message.timestamp !== undefined && (obj.timestamp = message.timestamp);
|
||||||
message.nick !== undefined && (obj.nick = message.nick);
|
message.nick !== undefined && (obj.nick = message.nick);
|
||||||
@ -84,8 +84,8 @@ export const ChatMessageProto = {
|
|||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
fromPartial(object: DeepPartial<ChatMessageProto>): ChatMessageProto {
|
fromPartial(object: DeepPartial<ChatMessage>): ChatMessage {
|
||||||
const message = { ...baseChatMessageProto } as ChatMessageProto;
|
const message = { ...baseChatMessage } as ChatMessage;
|
||||||
if (object.timestamp !== undefined && object.timestamp !== null) {
|
if (object.timestamp !== undefined && object.timestamp !== null) {
|
||||||
message.timestamp = object.timestamp;
|
message.timestamp = object.timestamp;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user