mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 13:53:12 +00:00
* remove react native package * upgrade nodejs * upgrade libp2p * upgrade typescript, use 22 node * up lock * fix node compatibility * upgrade playwright * upgrade proto * update tests
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
/* eslint-disable import/export */
|
|
/* eslint-disable complexity */
|
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
|
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
/* eslint-disable import/consistent-type-specifier-style */
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
import { decodeMessage, encodeMessage, message } from 'protons-runtime'
|
|
import type { Codec, DecodeOptions } from 'protons-runtime'
|
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
|
|
export interface TopicOnlyMessage {
|
|
contentTopic: string
|
|
}
|
|
|
|
export namespace TopicOnlyMessage {
|
|
let _codec: Codec<TopicOnlyMessage>
|
|
|
|
export const codec = (): Codec<TopicOnlyMessage> => {
|
|
if (_codec == null) {
|
|
_codec = message<TopicOnlyMessage>((obj, w, opts = {}) => {
|
|
if (opts.lengthDelimited !== false) {
|
|
w.fork()
|
|
}
|
|
|
|
if ((obj.contentTopic != null && obj.contentTopic !== '')) {
|
|
w.uint32(18)
|
|
w.string(obj.contentTopic)
|
|
}
|
|
|
|
if (opts.lengthDelimited !== false) {
|
|
w.ldelim()
|
|
}
|
|
}, (reader, length, opts = {}) => {
|
|
const obj: any = {
|
|
contentTopic: ''
|
|
}
|
|
|
|
const end = length == null ? reader.len : reader.pos + length
|
|
|
|
while (reader.pos < end) {
|
|
const tag = reader.uint32()
|
|
|
|
switch (tag >>> 3) {
|
|
case 2: {
|
|
obj.contentTopic = reader.string()
|
|
break
|
|
}
|
|
default: {
|
|
reader.skipType(tag & 7)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return obj
|
|
})
|
|
}
|
|
|
|
return _codec
|
|
}
|
|
|
|
export const encode = (obj: Partial<TopicOnlyMessage>): Uint8Array => {
|
|
return encodeMessage(obj, TopicOnlyMessage.codec())
|
|
}
|
|
|
|
export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<TopicOnlyMessage>): TopicOnlyMessage => {
|
|
return decodeMessage(buf, TopicOnlyMessage.codec(), opts)
|
|
}
|
|
}
|