From 3b7fc44419a278f2bcd9b88bca2c28f28c722611 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Mon, 10 May 2021 15:12:09 +1000 Subject: [PATCH] Remove `Proto` suffix Manage with namespace instead. --- proto/chat/v2/chat_message.proto | 2 +- src/lib/chat_message/index.ts | 6 +++--- src/proto/chat/v2/chat_message.ts | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/proto/chat/v2/chat_message.proto b/proto/chat/v2/chat_message.proto index 9d33bec91f..76b9524650 100644 --- a/proto/chat/v2/chat_message.proto +++ b/proto/chat/v2/chat_message.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package chat.v2; -message ChatMessageProto { +message ChatMessage { uint64 timestamp = 1; string nick = 2; bytes payload = 3; diff --git a/src/lib/chat_message/index.ts b/src/lib/chat_message/index.ts index db44448cb2..b9fd3046ec 100644 --- a/src/lib/chat_message/index.ts +++ b/src/lib/chat_message/index.ts @@ -1,6 +1,6 @@ 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? export class ChatMessage { @@ -11,7 +11,7 @@ export class 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 message = protoMsg.payload ? Array.from(protoMsg.payload) @@ -27,7 +27,7 @@ export class ChatMessage { const timestamp = Math.floor(this.timestamp.valueOf() / 1000); const payload = Buffer.from(this.message, 'utf-8'); - return ChatMessageProto.encode({ + return proto.ChatMessage.encode({ timestamp, nick: this.nick, payload, diff --git a/src/proto/chat/v2/chat_message.ts b/src/proto/chat/v2/chat_message.ts index 1d25d85cdf..9715ae63b7 100644 --- a/src/proto/chat/v2/chat_message.ts +++ b/src/proto/chat/v2/chat_message.ts @@ -4,17 +4,17 @@ import _m0 from 'protobufjs/minimal'; export const protobufPackage = 'chat.v2'; -export interface ChatMessageProto { +export interface ChatMessage { timestamp: number; nick: string; payload: Uint8Array; } -const baseChatMessageProto: object = { timestamp: 0, nick: '' }; +const baseChatMessage: object = { timestamp: 0, nick: '' }; -export const ChatMessageProto = { +export const ChatMessage = { encode( - message: ChatMessageProto, + message: ChatMessage, writer: _m0.Writer = _m0.Writer.create() ): _m0.Writer { if (message.timestamp !== 0) { @@ -29,10 +29,10 @@ export const ChatMessageProto = { 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); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseChatMessageProto } as ChatMessageProto; + const message = { ...baseChatMessage } as ChatMessage; message.payload = new Uint8Array(); while (reader.pos < end) { const tag = reader.uint32(); @@ -54,8 +54,8 @@ export const ChatMessageProto = { return message; }, - fromJSON(object: any): ChatMessageProto { - const message = { ...baseChatMessageProto } as ChatMessageProto; + fromJSON(object: any): ChatMessage { + const message = { ...baseChatMessage } as ChatMessage; message.payload = new Uint8Array(); if (object.timestamp !== undefined && object.timestamp !== null) { message.timestamp = Number(object.timestamp); @@ -73,7 +73,7 @@ export const ChatMessageProto = { return message; }, - toJSON(message: ChatMessageProto): unknown { + toJSON(message: ChatMessage): unknown { const obj: any = {}; message.timestamp !== undefined && (obj.timestamp = message.timestamp); message.nick !== undefined && (obj.nick = message.nick); @@ -84,8 +84,8 @@ export const ChatMessageProto = { return obj; }, - fromPartial(object: DeepPartial): ChatMessageProto { - const message = { ...baseChatMessageProto } as ChatMessageProto; + fromPartial(object: DeepPartial): ChatMessage { + const message = { ...baseChatMessage } as ChatMessage; if (object.timestamp !== undefined && object.timestamp !== null) { message.timestamp = object.timestamp; } else {