|
| 1 | +/* eslint-disable import/export */ |
| 2 | +/* eslint-disable complexity */ |
| 3 | +/* eslint-disable @typescript-eslint/no-namespace */ |
| 4 | +/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ |
| 5 | +/* eslint-disable @typescript-eslint/no-empty-interface */ |
| 6 | + |
| 7 | +import { encodeMessage, decodeMessage, message, CodeError } from 'protons-runtime' |
| 8 | +import type { Codec } from 'protons-runtime' |
| 9 | +import type { Uint8ArrayList } from 'uint8arraylist' |
| 10 | + |
| 11 | +export interface MessageWithSizeLimitedRepeatedField { |
| 12 | + repeatedField: string[] |
| 13 | +} |
| 14 | + |
| 15 | +export namespace MessageWithSizeLimitedRepeatedField { |
| 16 | + let _codec: Codec<MessageWithSizeLimitedRepeatedField> |
| 17 | + |
| 18 | + export const codec = (): Codec<MessageWithSizeLimitedRepeatedField> => { |
| 19 | + if (_codec == null) { |
| 20 | + _codec = message<MessageWithSizeLimitedRepeatedField>((obj, w, opts = {}) => { |
| 21 | + if (opts.lengthDelimited !== false) { |
| 22 | + w.fork() |
| 23 | + } |
| 24 | + |
| 25 | + if (obj.repeatedField != null) { |
| 26 | + for (const value of obj.repeatedField) { |
| 27 | + w.uint32(10) |
| 28 | + w.string(value) |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + if (opts.lengthDelimited !== false) { |
| 33 | + w.ldelim() |
| 34 | + } |
| 35 | + }, (reader, length) => { |
| 36 | + const obj: any = { |
| 37 | + repeatedField: [] |
| 38 | + } |
| 39 | + |
| 40 | + const end = length == null ? reader.len : reader.pos + length |
| 41 | + |
| 42 | + while (reader.pos < end) { |
| 43 | + const tag = reader.uint32() |
| 44 | + |
| 45 | + switch (tag >>> 3) { |
| 46 | + case 1: { |
| 47 | + if (obj.repeatedField.length === 1) { |
| 48 | + throw new CodeError('decode error - repeated field "repeatedField" had too many elements', 'ERR_MAX_LENGTH') |
| 49 | + } |
| 50 | + |
| 51 | + obj.repeatedField.push(reader.string()) |
| 52 | + break |
| 53 | + } |
| 54 | + default: { |
| 55 | + reader.skipType(tag & 7) |
| 56 | + break |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return obj |
| 62 | + }) |
| 63 | + } |
| 64 | + |
| 65 | + return _codec |
| 66 | + } |
| 67 | + |
| 68 | + export const encode = (obj: Partial<MessageWithSizeLimitedRepeatedField>): Uint8Array => { |
| 69 | + return encodeMessage(obj, MessageWithSizeLimitedRepeatedField.codec()) |
| 70 | + } |
| 71 | + |
| 72 | + export const decode = (buf: Uint8Array | Uint8ArrayList): MessageWithSizeLimitedRepeatedField => { |
| 73 | + return decodeMessage(buf, MessageWithSizeLimitedRepeatedField.codec()) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +export interface MessageWithSizeLimitedMap { |
| 78 | + mapField: Map<string, string> |
| 79 | +} |
| 80 | + |
| 81 | +export namespace MessageWithSizeLimitedMap { |
| 82 | + export interface MessageWithSizeLimitedMap$mapFieldEntry { |
| 83 | + key: string |
| 84 | + value: string |
| 85 | + } |
| 86 | + |
| 87 | + export namespace MessageWithSizeLimitedMap$mapFieldEntry { |
| 88 | + let _codec: Codec<MessageWithSizeLimitedMap$mapFieldEntry> |
| 89 | + |
| 90 | + export const codec = (): Codec<MessageWithSizeLimitedMap$mapFieldEntry> => { |
| 91 | + if (_codec == null) { |
| 92 | + _codec = message<MessageWithSizeLimitedMap$mapFieldEntry>((obj, w, opts = {}) => { |
| 93 | + if (opts.lengthDelimited !== false) { |
| 94 | + w.fork() |
| 95 | + } |
| 96 | + |
| 97 | + if ((obj.key != null && obj.key !== '')) { |
| 98 | + w.uint32(10) |
| 99 | + w.string(obj.key) |
| 100 | + } |
| 101 | + |
| 102 | + if ((obj.value != null && obj.value !== '')) { |
| 103 | + w.uint32(18) |
| 104 | + w.string(obj.value) |
| 105 | + } |
| 106 | + |
| 107 | + if (opts.lengthDelimited !== false) { |
| 108 | + w.ldelim() |
| 109 | + } |
| 110 | + }, (reader, length) => { |
| 111 | + const obj: any = { |
| 112 | + key: '', |
| 113 | + value: '' |
| 114 | + } |
| 115 | + |
| 116 | + const end = length == null ? reader.len : reader.pos + length |
| 117 | + |
| 118 | + while (reader.pos < end) { |
| 119 | + const tag = reader.uint32() |
| 120 | + |
| 121 | + switch (tag >>> 3) { |
| 122 | + case 1: { |
| 123 | + obj.key = reader.string() |
| 124 | + break |
| 125 | + } |
| 126 | + case 2: { |
| 127 | + obj.value = reader.string() |
| 128 | + break |
| 129 | + } |
| 130 | + default: { |
| 131 | + reader.skipType(tag & 7) |
| 132 | + break |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + return obj |
| 138 | + }) |
| 139 | + } |
| 140 | + |
| 141 | + return _codec |
| 142 | + } |
| 143 | + |
| 144 | + export const encode = (obj: Partial<MessageWithSizeLimitedMap$mapFieldEntry>): Uint8Array => { |
| 145 | + return encodeMessage(obj, MessageWithSizeLimitedMap$mapFieldEntry.codec()) |
| 146 | + } |
| 147 | + |
| 148 | + export const decode = (buf: Uint8Array | Uint8ArrayList): MessageWithSizeLimitedMap$mapFieldEntry => { |
| 149 | + return decodeMessage(buf, MessageWithSizeLimitedMap$mapFieldEntry.codec()) |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + let _codec: Codec<MessageWithSizeLimitedMap> |
| 154 | + |
| 155 | + export const codec = (): Codec<MessageWithSizeLimitedMap> => { |
| 156 | + if (_codec == null) { |
| 157 | + _codec = message<MessageWithSizeLimitedMap>((obj, w, opts = {}) => { |
| 158 | + if (opts.lengthDelimited !== false) { |
| 159 | + w.fork() |
| 160 | + } |
| 161 | + |
| 162 | + if (obj.mapField != null && obj.mapField.size !== 0) { |
| 163 | + for (const [key, value] of obj.mapField.entries()) { |
| 164 | + w.uint32(10) |
| 165 | + MessageWithSizeLimitedMap.MessageWithSizeLimitedMap$mapFieldEntry.codec().encode({ key, value }, w) |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + if (opts.lengthDelimited !== false) { |
| 170 | + w.ldelim() |
| 171 | + } |
| 172 | + }, (reader, length) => { |
| 173 | + const obj: any = { |
| 174 | + mapField: new Map<string, string>() |
| 175 | + } |
| 176 | + |
| 177 | + const end = length == null ? reader.len : reader.pos + length |
| 178 | + |
| 179 | + while (reader.pos < end) { |
| 180 | + const tag = reader.uint32() |
| 181 | + |
| 182 | + switch (tag >>> 3) { |
| 183 | + case 1: { |
| 184 | + if (obj.mapField.size === 1) { |
| 185 | + throw new CodeError('decode error - map field "mapField" had too many elements', 'ERR_MAX_SIZE') |
| 186 | + } |
| 187 | + |
| 188 | + const entry = MessageWithSizeLimitedMap.MessageWithSizeLimitedMap$mapFieldEntry.codec().decode(reader, reader.uint32()) |
| 189 | + obj.mapField.set(entry.key, entry.value) |
| 190 | + break |
| 191 | + } |
| 192 | + default: { |
| 193 | + reader.skipType(tag & 7) |
| 194 | + break |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + return obj |
| 200 | + }) |
| 201 | + } |
| 202 | + |
| 203 | + return _codec |
| 204 | + } |
| 205 | + |
| 206 | + export const encode = (obj: Partial<MessageWithSizeLimitedMap>): Uint8Array => { |
| 207 | + return encodeMessage(obj, MessageWithSizeLimitedMap.codec()) |
| 208 | + } |
| 209 | + |
| 210 | + export const decode = (buf: Uint8Array | Uint8ArrayList): MessageWithSizeLimitedMap => { |
| 211 | + return decodeMessage(buf, MessageWithSizeLimitedMap.codec()) |
| 212 | + } |
| 213 | +} |
0 commit comments