|
7 | 7 | import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime' |
8 | 8 | import type { Uint8ArrayList } from 'uint8arraylist' |
9 | 9 |
|
| 10 | +export interface HistoryEntry { |
| 11 | + messageId: string |
| 12 | + retrievalHint?: Uint8Array |
| 13 | +} |
| 14 | + |
| 15 | +export namespace HistoryEntry { |
| 16 | + let _codec: Codec<HistoryEntry> |
| 17 | + |
| 18 | + export const codec = (): Codec<HistoryEntry> => { |
| 19 | + if (_codec == null) { |
| 20 | + _codec = message<HistoryEntry>((obj, w, opts = {}) => { |
| 21 | + if (opts.lengthDelimited !== false) { |
| 22 | + w.fork() |
| 23 | + } |
| 24 | + |
| 25 | + if ((obj.messageId != null && obj.messageId !== '')) { |
| 26 | + w.uint32(10) |
| 27 | + w.string(obj.messageId) |
| 28 | + } |
| 29 | + |
| 30 | + if (obj.retrievalHint != null) { |
| 31 | + w.uint32(18) |
| 32 | + w.bytes(obj.retrievalHint) |
| 33 | + } |
| 34 | + |
| 35 | + if (opts.lengthDelimited !== false) { |
| 36 | + w.ldelim() |
| 37 | + } |
| 38 | + }, (reader, length, opts = {}) => { |
| 39 | + const obj: any = { |
| 40 | + messageId: '' |
| 41 | + } |
| 42 | + |
| 43 | + const end = length == null ? reader.len : reader.pos + length |
| 44 | + |
| 45 | + while (reader.pos < end) { |
| 46 | + const tag = reader.uint32() |
| 47 | + |
| 48 | + switch (tag >>> 3) { |
| 49 | + case 1: { |
| 50 | + obj.messageId = reader.string() |
| 51 | + break |
| 52 | + } |
| 53 | + case 2: { |
| 54 | + obj.retrievalHint = reader.bytes() |
| 55 | + break |
| 56 | + } |
| 57 | + default: { |
| 58 | + reader.skipType(tag & 7) |
| 59 | + break |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + return obj |
| 65 | + }) |
| 66 | + } |
| 67 | + |
| 68 | + return _codec |
| 69 | + } |
| 70 | + |
| 71 | + export const encode = (obj: Partial<HistoryEntry>): Uint8Array => { |
| 72 | + return encodeMessage(obj, HistoryEntry.codec()) |
| 73 | + } |
| 74 | + |
| 75 | + export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<HistoryEntry>): HistoryEntry => { |
| 76 | + return decodeMessage(buf, HistoryEntry.codec(), opts) |
| 77 | + } |
| 78 | +} |
| 79 | + |
10 | 80 | export interface SdsMessage { |
11 | 81 | messageId: string |
12 | 82 | channelId: string |
13 | 83 | lamportTimestamp?: number |
14 | | - causalHistory: string[] |
| 84 | + causalHistory: HistoryEntry[] |
15 | 85 | bloomFilter?: Uint8Array |
16 | 86 | content?: Uint8Array |
17 | 87 | } |
@@ -44,7 +114,7 @@ export namespace SdsMessage { |
44 | 114 | if (obj.causalHistory != null) { |
45 | 115 | for (const value of obj.causalHistory) { |
46 | 116 | w.uint32(90) |
47 | | - w.string(value) |
| 117 | + HistoryEntry.codec().encode(value, w) |
48 | 118 | } |
49 | 119 | } |
50 | 120 |
|
@@ -91,7 +161,9 @@ export namespace SdsMessage { |
91 | 161 | throw new MaxLengthError('Decode error - map field "causalHistory" had too many elements') |
92 | 162 | } |
93 | 163 |
|
94 | | - obj.causalHistory.push(reader.string()) |
| 164 | + obj.causalHistory.push(HistoryEntry.codec().decode(reader, reader.uint32(), { |
| 165 | + limits: opts.limits?.causalHistory$ |
| 166 | + })) |
95 | 167 | break |
96 | 168 | } |
97 | 169 | case 12: { |
|
0 commit comments