You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: packages/protons/README.md
+56
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,9 @@
12
12
-[Install](#install)
13
13
-[Usage](#usage)
14
14
-[Differences from protobuf.js](#differences-from-protobufjs)
15
+
-[Extra features](#extra-features)
16
+
-[Limiting the size of repeated/map elements](#limiting-the-size-of-repeatedmap-elements)
17
+
-[Overriding 64 bit types](#overriding-64-bit-types)
15
18
-[Missing features](#missing-features)
16
19
-[API Docs](#api-docs)
17
20
-[License](#license)
@@ -73,6 +76,59 @@ It does have one or two differences:
73
76
5.`map` fields can have keys of any type - protobufs.js [only supports strings](https://github.com/protobufjs/protobuf.js/issues/1203#issuecomment-488637338)
74
77
6.`map` fields are deserialized as ES6 `Map`s - protobuf.js uses `Object`s
75
78
79
+
## Extra features
80
+
81
+
### Limiting the size of repeated/map elements
82
+
83
+
To protect decoders from malicious payloads, it's possible to limit the maximum size of repeated/map elements.
84
+
85
+
You can either do this at compile time by using the [protons.options](https://github.com/protocolbuffers/protobuf/blob/6f1d88107f268b8ebdad6690d116e74c403e366e/docs/options.md?plain=1#L490-L493) extension:
Or at runtime by passing objects to the `.decode` function of your message:
98
+
99
+
```TypeScript
100
+
const message =MyMessage.decode(buf, {
101
+
limits: {
102
+
repeatedField: 10,
103
+
stringMap: 10
104
+
}
105
+
})
106
+
```
107
+
108
+
### Overriding 64 bit types
109
+
110
+
By default 64 bit types are implemented as [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)s.
111
+
112
+
Sometimes this is undesirable due to [performance issues](https://betterprogramming.pub/the-downsides-of-bigints-in-javascript-6350fd807d) or code legibility.
113
+
114
+
It's possible to override the JavaScript type 64 bit fields will deserialize to:
Some features are missing `OneOf`s, etc due to them not being needed so far in ipfs/libp2p. If these features are important to you, please open PRs implementing them along with tests comparing the generated bytes to `protobuf.js` and `pbjs`.
0 commit comments