@aptre/protobuf-es-lite 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/.ignore +1 -0
  2. package/README.md +23 -24
  3. package/bin/protoc-gen-es-lite +2 -2
  4. package/dist/binary-encoding.d.ts +420 -0
  5. package/dist/binary-encoding.js +437 -0
  6. package/dist/binary.d.ts +35 -2
  7. package/dist/binary.js +64 -65
  8. package/dist/codegen-info.d.ts +43 -0
  9. package/dist/codegen-info.js +72 -0
  10. package/dist/create-descriptor-set.d.ts +36 -0
  11. package/dist/create-descriptor-set.js +936 -0
  12. package/dist/descriptor-set.d.ts +672 -0
  13. package/dist/{editions.js → descriptor-set.js} +0 -11
  14. package/dist/enum.d.ts +35 -1
  15. package/dist/feature-set.d.ts +19 -0
  16. package/dist/feature-set.js +103 -0
  17. package/dist/field-wrapper.d.ts +7 -3
  18. package/dist/field-wrapper.js +30 -1
  19. package/dist/field.d.ts +8 -19
  20. package/dist/field.js +15 -117
  21. package/dist/google/index.d.ts +9 -0
  22. package/dist/google/index.js +41 -0
  23. package/dist/google/protobuf/any.pb.d.ts +139 -0
  24. package/dist/google/protobuf/any.pb.js +42 -0
  25. package/dist/google/protobuf/api.pb.d.ts +252 -0
  26. package/dist/google/protobuf/api.pb.js +70 -0
  27. package/dist/google/protobuf/compiler/plugin.pb.d.ts +240 -0
  28. package/dist/google/protobuf/compiler/plugin.pb.js +203 -0
  29. package/dist/google/protobuf/descriptor.pb.d.ts +2132 -0
  30. package/dist/google/protobuf/descriptor.pb.js +1080 -0
  31. package/dist/google/protobuf/duration.pb.d.ts +92 -0
  32. package/dist/google/protobuf/duration.pb.js +42 -0
  33. package/dist/google/protobuf/empty.pb.d.ts +18 -0
  34. package/dist/google/protobuf/empty.pb.js +39 -0
  35. package/dist/google/protobuf/source_context.pb.d.ts +21 -0
  36. package/dist/google/protobuf/source_context.pb.js +41 -0
  37. package/dist/google/protobuf/struct.pb.d.ts +121 -0
  38. package/dist/google/protobuf/struct.pb.js +83 -0
  39. package/dist/google/protobuf/timestamp.pb.d.ts +121 -0
  40. package/dist/google/protobuf/timestamp.pb.js +42 -0
  41. package/dist/google/protobuf/type.pb.d.ts +464 -0
  42. package/dist/google/protobuf/type.pb.js +338 -0
  43. package/dist/google/protobuf/wrappers.pb.d.ts +183 -0
  44. package/dist/google/protobuf/wrappers.pb.js +107 -0
  45. package/dist/index.d.ts +9 -3
  46. package/dist/index.js +41 -8
  47. package/dist/is-message.d.ts +10 -2
  48. package/dist/is-message.js +74 -3
  49. package/dist/json.d.ts +68 -1
  50. package/dist/json.js +57 -81
  51. package/dist/message.d.ts +30 -61
  52. package/dist/message.js +61 -20
  53. package/dist/names.d.ts +43 -0
  54. package/dist/names.js +276 -0
  55. package/dist/partial.js +14 -15
  56. package/dist/proto-base64.d.ts +18 -0
  57. package/dist/proto-base64.js +128 -0
  58. package/dist/proto-double.d.ts +5 -0
  59. package/dist/proto-double.js +29 -0
  60. package/dist/proto-int64.d.ts +95 -0
  61. package/dist/proto-int64.js +116 -0
  62. package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.d.ts +1 -0
  63. package/dist/{protoc-gen-es-lite-plugin.js → protoc-gen-es-lite/protoc-gen-es-lite-plugin.js} +2 -2
  64. package/dist/{typescript.d.ts → protoc-gen-es-lite/typescript.d.ts} +3 -2
  65. package/dist/{typescript.js → protoc-gen-es-lite/typescript.js} +46 -34
  66. package/dist/protoplugin/create-es-plugin.d.ts +83 -0
  67. package/dist/protoplugin/create-es-plugin.js +119 -0
  68. package/dist/protoplugin/ecmascript/file-preamble.d.ts +2 -0
  69. package/dist/protoplugin/ecmascript/file-preamble.js +74 -0
  70. package/dist/protoplugin/ecmascript/generated-file.d.ts +116 -0
  71. package/dist/protoplugin/ecmascript/generated-file.js +407 -0
  72. package/dist/protoplugin/ecmascript/import-path.d.ts +65 -0
  73. package/dist/protoplugin/ecmascript/import-path.js +156 -0
  74. package/dist/protoplugin/ecmascript/import-symbol.d.ts +39 -0
  75. package/dist/protoplugin/ecmascript/import-symbol.js +37 -0
  76. package/dist/protoplugin/ecmascript/index.d.ts +7 -0
  77. package/dist/protoplugin/ecmascript/index.js +20 -0
  78. package/dist/protoplugin/ecmascript/jsdoc.d.ts +14 -0
  79. package/dist/protoplugin/ecmascript/jsdoc.js +93 -0
  80. package/dist/protoplugin/ecmascript/opaque-printables.d.ts +27 -0
  81. package/dist/protoplugin/ecmascript/opaque-printables.js +15 -0
  82. package/dist/protoplugin/ecmascript/parameter.d.ts +13 -0
  83. package/dist/protoplugin/ecmascript/parameter.js +161 -0
  84. package/dist/protoplugin/ecmascript/reify-wkt.d.ts +100 -0
  85. package/dist/protoplugin/ecmascript/reify-wkt.js +170 -0
  86. package/dist/protoplugin/ecmascript/runtime-imports.d.ts +6 -0
  87. package/dist/protoplugin/ecmascript/runtime-imports.js +28 -0
  88. package/dist/protoplugin/ecmascript/schema.d.ts +43 -0
  89. package/dist/protoplugin/ecmascript/schema.js +73 -0
  90. package/dist/protoplugin/ecmascript/target.d.ts +4 -0
  91. package/dist/protoplugin/ecmascript/target.js +15 -0
  92. package/dist/protoplugin/ecmascript/transpile.d.ts +2 -0
  93. package/dist/protoplugin/ecmascript/transpile.js +149 -0
  94. package/dist/protoplugin/error.d.ts +6 -0
  95. package/dist/protoplugin/error.js +43 -0
  96. package/dist/protoplugin/index.d.ts +8 -0
  97. package/dist/protoplugin/index.js +20 -0
  98. package/dist/protoplugin/plugin.d.ts +18 -0
  99. package/dist/protoplugin/plugin.js +15 -0
  100. package/dist/protoplugin/run-node.d.ts +12 -0
  101. package/dist/protoplugin/run-node.js +83 -0
  102. package/dist/scalar.d.ts +53 -1
  103. package/dist/scalar.js +87 -22
  104. package/dist/service-type.d.ts +95 -0
  105. package/dist/service-type.js +53 -0
  106. package/dist/text-format.d.ts +4 -0
  107. package/dist/text-format.js +189 -0
  108. package/dist/type-registry.d.ts +43 -0
  109. package/dist/type-registry.js +15 -0
  110. package/dist/unknown.d.ts +1 -1
  111. package/dist/util.d.ts +2 -2
  112. package/dist/util.js +46 -44
  113. package/dist/varint.d.ts +70 -0
  114. package/dist/varint.js +324 -0
  115. package/example/example.pb.ts +87 -0
  116. package/example/example.proto +1 -0
  117. package/example/tsconfig.json +8 -2
  118. package/package.json +19 -12
  119. package/tsconfig.json +4 -4
  120. package/dist/editions.d.ts +0 -6
  121. package/dist/protoc-gen-es-lite-plugin.d.ts +0 -1
package/.ignore CHANGED
@@ -2,3 +2,4 @@ node_modules/
2
2
  *.pb.go
3
3
  *.pb.ts
4
4
  go.sum
5
+ dist/
package/README.md CHANGED
@@ -9,9 +9,9 @@
9
9
 
10
10
  protobuf-es-lite is a TypeScript and JavaScript protobuf implementation.
11
11
 
12
- It uses [@bufbuild/protoplugin] to implement **protoc-gen-es-lite** which generates js and/or ts code.
12
+ It uses [protoplugin] to implement **protoc-gen-es-lite** which generates js and/or ts code.
13
13
 
14
- [@bufbuild/protoplugin]: https://github.com/bufbuild/protobuf-es/tree/main/packages/protoplugin
14
+ [protoplugin]: ./src/protoplugin
15
15
 
16
16
  See [protobuf-es] for information about protoplugin.
17
17
 
@@ -53,8 +53,11 @@ using interfaces and plain messages everywhere and does not need classes.
53
53
  This fork generates the ts-proto style with the protoc-gen-es tools:
54
54
 
55
55
  ```typescript
56
+ // Create a partial MyMessage with just one field sets.
56
57
  const myMessage: MyMessage = {body: "Hello world"}
57
- const myCompleteMessage: CompleteMessage<MyMessage> = MyMessage.create(myMessage)
58
+ // Creates a version of MyMessage filled with zeros.
59
+ const myCompleteMessage: MyMessage = MyMessage.create(myMessage)
60
+ // Convert MyMessage to binary.
58
61
  const myMessageBin = MyMessage.toBinary(myCompleteMessage)
59
62
  ```
60
63
 
@@ -63,21 +66,18 @@ const myMessageBin = MyMessage.toBinary(myCompleteMessage)
63
66
  ## Installation
64
67
 
65
68
  `protoc-gen-es` generates base types - messages and enumerations - from your
66
- Protocol Buffer schema. The generated code requires the runtime library
67
- [@bufbuild/protobuf].
68
-
69
- [@bufbuild/protobuf]: https://www.npmjs.com/package/@bufbuild/protobuf
69
+ Protocol Buffer schema.
70
70
 
71
71
  To install the plugin and the runtime library, run:
72
72
 
73
73
  ```shell
74
- npm install --save-dev @aptre/protoc-gen-es-lite
75
- npm install @bufbuild/protobuf
74
+ npm install @aptre/protoc-gen-es-lite
76
75
  ```
77
76
 
78
77
  We use peer dependencies to ensure that code generator and runtime library are
79
78
  compatible with each other. Note that npm installs them automatically, but yarn
80
79
  and pnpm do not.
80
+
81
81
  ## Generating code
82
82
 
83
83
  ### With buf
@@ -93,10 +93,10 @@ Add a new configuration file `buf.gen.yaml`:
93
93
  # For details, see https://docs.buf.build/configuration/v1/buf-gen-yaml
94
94
  version: v1
95
95
  plugins:
96
- # This will invoke protoc-gen-es and write output to src/gen
97
- - plugin: es
96
+ # This will invoke protoc-gen-es-lite and write output to src/gen
97
+ - plugin: es-lite
98
98
  out: src/gen
99
- opt:
99
+ opt:
100
100
  # Add more plugin options here
101
101
  - target=ts
102
102
  ```
@@ -108,16 +108,15 @@ npx buf generate
108
108
  ```
109
109
 
110
110
  Note that `buf` can generate from various [inputs](https://docs.buf.build/reference/inputs),
111
- not just local protobuf files.
112
-
111
+ not just local protobuf files.
113
112
 
114
113
  ### With protoc
115
114
 
116
115
  ```bash
117
116
  PATH=$PATH:$(pwd)/node_modules/.bin \
118
117
  protoc -I . \
119
- --es_out src/gen \
120
- --es_opt target=ts \
118
+ --es-lite_out src/gen \
119
+ --es-lite_opt target=ts \
121
120
  a.proto b.proto c.proto
122
121
  ```
123
122
 
@@ -128,7 +127,7 @@ Since yarn v2 and above does not use a `node_modules` directory, you need to
128
127
  change the variable a bit:
129
128
 
130
129
  ```bash
131
- PATH=$(dirname $(yarn bin protoc-gen-es)):$PATH
130
+ PATH=$(dirname $(yarn bin protoc-gen-es-lite)):$PATH
132
131
  ```
133
132
 
134
133
  ## Plugin options
@@ -139,9 +138,9 @@ This option controls whether the plugin generates JavaScript, TypeScript,
139
138
  or TypeScript declaration files.
140
139
 
141
140
  Possible values:
142
- - `target=js` - generates a `_pb.js` file for every `.proto` input file.
143
- - `target=ts` - generates a `_pb.ts` file for every `.proto` input file.
144
- - `target=dts` - generates a `_pb.d.ts` file for every `.proto` input file.
141
+ - `target=js` - generates a `.pb.js` file for every `.proto` input file.
142
+ - `target=ts` - generates a `.pb.ts` file for every `.proto` input file.
143
+ - `target=dts` - generates a `.pb.d.ts` file for every `.proto` input file.
145
144
 
146
145
  Multiple values can be given by separating them with `+`, for example
147
146
  `target=js+dts`.
@@ -153,7 +152,7 @@ bundler configurations. If you prefer to generate TypeScript, use `target=ts`.
153
152
  ### `import_extension=.js`
154
153
 
155
154
  By default, [protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-es)
156
- (and all other plugins based on [@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin))
155
+ (and all other plugins based on [@aptre/protobuf-es-lite/protoplugin](https://www.npmjs.com/package/@aptre/protobuf-es-lite/protoplugin))
157
156
  uses a `.js` file extensions in import paths, even in TypeScript files.
158
157
 
159
158
  This is unintuitive, but necessary for [ECMAScript modules in Node.js](https://www.typescriptlang.org/docs/handbook/esm-node.html).
@@ -167,7 +166,7 @@ in import paths with the given value. For example, set
167
166
  ### `js_import_style`
168
167
 
169
168
  By default, [protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-es)
170
- (and all other plugins based on [@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin))
169
+ (and all other plugins based on [@aptre/protobuf-es-lite/protoplugin](https://www.npmjs.com/package/@aptre/protobuf-es-lite/protoplugin))
171
170
  generate ECMAScript `import` and `export` statements. For use cases where
172
171
  CommonJS is difficult to avoid, this option can be used to generate CommonJS
173
172
  `require()` calls.
@@ -180,7 +179,7 @@ Possible values:
180
179
  ### `keep_empty_files=true`
181
180
 
182
181
  By default, [protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-es)
183
- (and all other plugins based on [@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin))
182
+ (and all other plugins based on [@aptre/protobuf-es-lite/protoplugin](https://www.npmjs.com/package/@aptre/protobuf-es-lite/protoplugin))
184
183
  omit empty files from the plugin output. This option disables pruning of
185
184
  empty files, to allow for smooth interoperation with Bazel and similar
186
185
  tooling that requires all output files to be declared ahead of time.
@@ -189,7 +188,7 @@ Unless you use Bazel, it is very unlikely that you need this option.
189
188
  ### `ts_nocheck=false`
190
189
 
191
190
  By default, [protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-es)
192
- (and all other plugins based on [@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin))
191
+ (and all other plugins based on [@aptre/protobuf-es-lite/protoplugin](https://www.npmjs.com/package/@aptre/protobuf-es-lite/protoplugin))
193
192
  generate an annotation at the top of each file: `// @ts-nocheck`.
194
193
 
195
194
  We generate the annotation to support a wide range of compiler configurations and
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const {runNodeJs} = require("@bufbuild/protoplugin");
4
- const {protocGenEsLite} = require("../dist/protoc-gen-es-lite-plugin.js");
3
+ const {runNodeJs} = require("../dist/protoplugin");
4
+ const {protocGenEsLite} = require("../dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js");
5
5
 
6
6
  runNodeJs(protocGenEsLite);
@@ -0,0 +1,420 @@
1
+ /**
2
+ * Protobuf binary format wire types.
3
+ *
4
+ * A wire type provides just enough information to find the length of the
5
+ * following value.
6
+ *
7
+ * See https://developers.google.com/protocol-buffers/docs/encoding#structure
8
+ */
9
+ export declare enum WireType {
10
+ /**
11
+ * Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum
12
+ */
13
+ Varint = 0,
14
+ /**
15
+ * Used for fixed64, sfixed64, double.
16
+ * Always 8 bytes with little-endian byte order.
17
+ */
18
+ Bit64 = 1,
19
+ /**
20
+ * Used for string, bytes, embedded messages, packed repeated fields
21
+ *
22
+ * Only repeated numeric types (types which use the varint, 32-bit,
23
+ * or 64-bit wire types) can be packed. In proto3, such fields are
24
+ * packed by default.
25
+ */
26
+ LengthDelimited = 2,
27
+ /**
28
+ * Start of a tag-delimited aggregate, such as a proto2 group, or a message
29
+ * in editions with message_encoding = DELIMITED.
30
+ */
31
+ StartGroup = 3,
32
+ /**
33
+ * End of a tag-delimited aggregate.
34
+ */
35
+ EndGroup = 4,
36
+ /**
37
+ * Used for fixed32, sfixed32, float.
38
+ * Always 4 bytes with little-endian byte order.
39
+ */
40
+ Bit32 = 5
41
+ }
42
+ type TextEncoderLike = {
43
+ encode(input?: string): Uint8Array;
44
+ };
45
+ type TextDecoderLike = {
46
+ decode(input?: Uint8Array): string;
47
+ };
48
+ export interface IBinaryReader {
49
+ /**
50
+ * Current position.
51
+ */
52
+ readonly pos: number;
53
+ /**
54
+ * Number of bytes available in this reader.
55
+ */
56
+ readonly len: number;
57
+ /**
58
+ * Reads a tag - field number and wire type.
59
+ */
60
+ tag(): [number, WireType];
61
+ /**
62
+ * Skip one element on the wire and return the skipped data.
63
+ */
64
+ skip(wireType: WireType): Uint8Array;
65
+ /**
66
+ * Read a `uint32` field, an unsigned 32 bit varint.
67
+ */
68
+ uint32(): number;
69
+ /**
70
+ * Read a `int32` field, a signed 32 bit varint.
71
+ */
72
+ int32(): number;
73
+ /**
74
+ * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
75
+ */
76
+ sint32(): number;
77
+ /**
78
+ * Read a `int64` field, a signed 64-bit varint.
79
+ */
80
+ int64(): bigint | string;
81
+ /**
82
+ * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
83
+ */
84
+ sint64(): bigint | string;
85
+ /**
86
+ * Read a `fixed64` field, a signed, fixed-length 64-bit integer.
87
+ */
88
+ sfixed64(): bigint | string;
89
+ /**
90
+ * Read a `uint64` field, an unsigned 64-bit varint.
91
+ */
92
+ uint64(): bigint | string;
93
+ /**
94
+ * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
95
+ */
96
+ fixed64(): bigint | string;
97
+ /**
98
+ * Read a `bool` field, a variant.
99
+ */
100
+ bool(): boolean;
101
+ /**
102
+ * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
103
+ */
104
+ fixed32(): number;
105
+ /**
106
+ * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
107
+ */
108
+ sfixed32(): number;
109
+ /**
110
+ * Read a `float` field, 32-bit floating point number.
111
+ */
112
+ float(): number;
113
+ /**
114
+ * Read a `double` field, a 64-bit floating point number.
115
+ */
116
+ double(): number;
117
+ /**
118
+ * Read a `bytes` field, length-delimited arbitrary data.
119
+ */
120
+ bytes(): Uint8Array;
121
+ /**
122
+ * Read a `string` field, length-delimited data converted to UTF-8 text.
123
+ */
124
+ string(): string;
125
+ }
126
+ export interface IBinaryWriter {
127
+ /**
128
+ * Return all bytes written and reset this writer.
129
+ */
130
+ finish(): Uint8Array;
131
+ /**
132
+ * Start a new fork for length-delimited data like a message
133
+ * or a packed repeated field.
134
+ *
135
+ * Must be joined later with `join()`.
136
+ */
137
+ fork(): IBinaryWriter;
138
+ /**
139
+ * Join the last fork. Write its length and bytes, then
140
+ * return to the previous state.
141
+ */
142
+ join(): IBinaryWriter;
143
+ /**
144
+ * Writes a tag (field number and wire type).
145
+ *
146
+ * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`
147
+ *
148
+ * Generated code should compute the tag ahead of time and call `uint32()`.
149
+ */
150
+ tag(fieldNo: number, type: WireType): IBinaryWriter;
151
+ /**
152
+ * Write a chunk of raw bytes.
153
+ */
154
+ raw(chunk: Uint8Array): IBinaryWriter;
155
+ /**
156
+ * Write a `uint32` value, an unsigned 32 bit varint.
157
+ */
158
+ uint32(value: number): IBinaryWriter;
159
+ /**
160
+ * Write a `int32` value, a signed 32 bit varint.
161
+ */
162
+ int32(value: number): IBinaryWriter;
163
+ /**
164
+ * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
165
+ */
166
+ sint32(value: number): IBinaryWriter;
167
+ /**
168
+ * Write a `int64` value, a signed 64-bit varint.
169
+ */
170
+ int64(value: string | number | bigint): IBinaryWriter;
171
+ /**
172
+ * Write a `uint64` value, an unsigned 64-bit varint.
173
+ */
174
+ uint64(value: string | number | bigint): IBinaryWriter;
175
+ /**
176
+ * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
177
+ */
178
+ sint64(value: string | number | bigint): IBinaryWriter;
179
+ /**
180
+ * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
181
+ */
182
+ fixed64(value: string | number | bigint): IBinaryWriter;
183
+ /**
184
+ * Write a `fixed64` value, a signed, fixed-length 64-bit integer.
185
+ */
186
+ sfixed64(value: string | number | bigint): IBinaryWriter;
187
+ /**
188
+ * Write a `bool` value, a variant.
189
+ */
190
+ bool(value: boolean): IBinaryWriter;
191
+ /**
192
+ * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
193
+ */
194
+ fixed32(value: number): IBinaryWriter;
195
+ /**
196
+ * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
197
+ */
198
+ sfixed32(value: number): IBinaryWriter;
199
+ /**
200
+ * Write a `float` value, 32-bit floating point number.
201
+ */
202
+ float(value: number): IBinaryWriter;
203
+ /**
204
+ * Write a `double` value, a 64-bit floating point number.
205
+ */
206
+ double(value: number): IBinaryWriter;
207
+ /**
208
+ * Write a `bytes` value, length-delimited arbitrary data.
209
+ */
210
+ bytes(value: Uint8Array): IBinaryWriter;
211
+ /**
212
+ * Write a `string` value, length-delimited data converted to UTF-8 text.
213
+ */
214
+ string(value: string): IBinaryWriter;
215
+ }
216
+ export declare class BinaryWriter implements IBinaryWriter {
217
+ /**
218
+ * We cannot allocate a buffer for the entire output
219
+ * because we don't know it's size.
220
+ *
221
+ * So we collect smaller chunks of known size and
222
+ * concat them later.
223
+ *
224
+ * Use `raw()` to push data to this array. It will flush
225
+ * `buf` first.
226
+ */
227
+ private chunks;
228
+ /**
229
+ * A growing buffer for byte values. If you don't know
230
+ * the size of the data you are writing, push to this
231
+ * array.
232
+ */
233
+ protected buf: number[];
234
+ /**
235
+ * Previous fork states.
236
+ */
237
+ private stack;
238
+ /**
239
+ * Text encoder instance to convert UTF-8 to bytes.
240
+ */
241
+ private readonly textEncoder;
242
+ constructor(textEncoder?: TextEncoderLike);
243
+ /**
244
+ * Return all bytes written and reset this writer.
245
+ */
246
+ finish(): Uint8Array;
247
+ /**
248
+ * Start a new fork for length-delimited data like a message
249
+ * or a packed repeated field.
250
+ *
251
+ * Must be joined later with `join()`.
252
+ */
253
+ fork(): IBinaryWriter;
254
+ /**
255
+ * Join the last fork. Write its length and bytes, then
256
+ * return to the previous state.
257
+ */
258
+ join(): IBinaryWriter;
259
+ /**
260
+ * Writes a tag (field number and wire type).
261
+ *
262
+ * Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`.
263
+ *
264
+ * Generated code should compute the tag ahead of time and call `uint32()`.
265
+ */
266
+ tag(fieldNo: number, type: WireType): IBinaryWriter;
267
+ /**
268
+ * Write a chunk of raw bytes.
269
+ */
270
+ raw(chunk: Uint8Array): IBinaryWriter;
271
+ /**
272
+ * Write a `uint32` value, an unsigned 32 bit varint.
273
+ */
274
+ uint32(value: number): IBinaryWriter;
275
+ /**
276
+ * Write a `int32` value, a signed 32 bit varint.
277
+ */
278
+ int32(value: number): IBinaryWriter;
279
+ /**
280
+ * Write a `bool` value, a variant.
281
+ */
282
+ bool(value: boolean): IBinaryWriter;
283
+ /**
284
+ * Write a `bytes` value, length-delimited arbitrary data.
285
+ */
286
+ bytes(value: Uint8Array): IBinaryWriter;
287
+ /**
288
+ * Write a `string` value, length-delimited data converted to UTF-8 text.
289
+ */
290
+ string(value: string): IBinaryWriter;
291
+ /**
292
+ * Write a `float` value, 32-bit floating point number.
293
+ */
294
+ float(value: number): IBinaryWriter;
295
+ /**
296
+ * Write a `double` value, a 64-bit floating point number.
297
+ */
298
+ double(value: number): IBinaryWriter;
299
+ /**
300
+ * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
301
+ */
302
+ fixed32(value: number): IBinaryWriter;
303
+ /**
304
+ * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
305
+ */
306
+ sfixed32(value: number): IBinaryWriter;
307
+ /**
308
+ * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
309
+ */
310
+ sint32(value: number): IBinaryWriter;
311
+ /**
312
+ * Write a `fixed64` value, a signed, fixed-length 64-bit integer.
313
+ */
314
+ sfixed64(value: string | number | bigint): IBinaryWriter;
315
+ /**
316
+ * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
317
+ */
318
+ fixed64(value: string | number | bigint): IBinaryWriter;
319
+ /**
320
+ * Write a `int64` value, a signed 64-bit varint.
321
+ */
322
+ int64(value: string | number | bigint): IBinaryWriter;
323
+ /**
324
+ * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
325
+ */
326
+ sint64(value: string | number | bigint): IBinaryWriter;
327
+ /**
328
+ * Write a `uint64` value, an unsigned 64-bit varint.
329
+ */
330
+ uint64(value: string | number | bigint): IBinaryWriter;
331
+ }
332
+ export declare class BinaryReader implements IBinaryReader {
333
+ /**
334
+ * Current position.
335
+ */
336
+ pos: number;
337
+ /**
338
+ * Number of bytes available in this reader.
339
+ */
340
+ readonly len: number;
341
+ private readonly buf;
342
+ private readonly view;
343
+ private readonly textDecoder;
344
+ constructor(buf: Uint8Array, textDecoder?: TextDecoderLike);
345
+ /**
346
+ * Reads a tag - field number and wire type.
347
+ */
348
+ tag(): [number, WireType];
349
+ /**
350
+ * Skip one element on the wire and return the skipped data.
351
+ * Supports WireType.StartGroup since v2.0.0-alpha.23.
352
+ */
353
+ skip(wireType: WireType): Uint8Array;
354
+ protected varint64: () => [number, number];
355
+ /**
356
+ * Throws error if position in byte array is out of range.
357
+ */
358
+ protected assertBounds(): void;
359
+ /**
360
+ * Read a `uint32` field, an unsigned 32 bit varint.
361
+ */
362
+ uint32: () => number;
363
+ /**
364
+ * Read a `int32` field, a signed 32 bit varint.
365
+ */
366
+ int32(): number;
367
+ /**
368
+ * Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
369
+ */
370
+ sint32(): number;
371
+ /**
372
+ * Read a `int64` field, a signed 64-bit varint.
373
+ */
374
+ int64(): bigint | string;
375
+ /**
376
+ * Read a `uint64` field, an unsigned 64-bit varint.
377
+ */
378
+ uint64(): bigint | string;
379
+ /**
380
+ * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
381
+ */
382
+ sint64(): bigint | string;
383
+ /**
384
+ * Read a `bool` field, a variant.
385
+ */
386
+ bool(): boolean;
387
+ /**
388
+ * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
389
+ */
390
+ fixed32(): number;
391
+ /**
392
+ * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
393
+ */
394
+ sfixed32(): number;
395
+ /**
396
+ * Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
397
+ */
398
+ fixed64(): bigint | string;
399
+ /**
400
+ * Read a `fixed64` field, a signed, fixed-length 64-bit integer.
401
+ */
402
+ sfixed64(): bigint | string;
403
+ /**
404
+ * Read a `float` field, 32-bit floating point number.
405
+ */
406
+ float(): number;
407
+ /**
408
+ * Read a `double` field, a 64-bit floating point number.
409
+ */
410
+ double(): number;
411
+ /**
412
+ * Read a `bytes` field, length-delimited arbitrary data.
413
+ */
414
+ bytes(): Uint8Array;
415
+ /**
416
+ * Read a `string` field, length-delimited data converted to UTF-8 text.
417
+ */
418
+ string(): string;
419
+ }
420
+ export {};