Skip to content

Commit 7463c53

Browse files
committed
doc
1 parent 4cec7f1 commit 7463c53

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ const extensionCodec = new ExtensionCodec();
5353
// Set<T>
5454
extensionCodec.register({
5555
type: 0,
56-
encode: (object: unknown) => {
56+
encode: (object: unknown): Uint8Array | null => {
5757
if (object instanceof Set) {
5858
return encode([...object]);
5959
} else {
6060
return null;
6161
}
6262
},
63-
decode: (data) => {
63+
decode: (data: Uint8Array) => {
6464
const array = decode(data) as Array<any>;
6565
return new Set(array);
6666
},
@@ -69,14 +69,14 @@ extensionCodec.register({
6969
// Map<T>
7070
extensionCodec.register({
7171
type: 1,
72-
encode: (object: unknown) => {
72+
encode: (object: unknown): Uint8Array => {
7373
if (object instanceof Map) {
7474
return encode([...object]);
7575
} else {
7676
return null;
7777
}
7878
},
79-
decode: (data) => {
79+
decode: (data: Uint8Array) => {
8080
const array = decode(data) as Array<[unknown, unknown]>;
8181
return new Map(array);
8282
},
@@ -91,6 +91,18 @@ const decoded = decode(encoded, { extensionCodec });
9191

9292
Not that extension types for custom objects must be `[0, 127]`, while `[-1, -128]` is reserved to MessagePack itself.
9393

94+
## Prerequsites
95+
96+
* ES5 language features
97+
* Typed Arrays (ES2015; [Can I use Typed Arrays?](https://caniuse.com/#feat=typedarrays))
98+
* String.prototype.padStart (ES2017; [caniuse](https://caniuse.com/#feat=pad-start-end))
99+
100+
You can use polyfills for them.
101+
102+
### NodeJS
103+
104+
If you use this library in NodeJS, v10 or later is required.
105+
94106
## Distrubition
95107

96108
The NPM package distributed in npmjs.com includes both ES2015+ and ES5 files:

src/Encoder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export class Encoder {
4444
}
4545

4646
resizeBuffer(newSize: number) {
47-
// TODO: ensure the size to be multiple of 4 and use Uint32Array for performance
4847
const newBuffer = new ArrayBuffer(newSize);
4948

5049
new Uint8Array(newBuffer).set(new Uint8Array(this.view.buffer));

test/ExtensionCodec.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ describe("ExtensionCodec", () => {
4444
// Set<T>
4545
extensionCodec.register({
4646
type: 0,
47-
encode: (object: unknown) => {
47+
encode: (object: unknown): Uint8Array | null => {
4848
if (object instanceof Set) {
4949
return encode([...object]);
5050
} else {
5151
return null;
5252
}
5353
},
54-
decode: (data) => {
54+
decode: (data: Uint8Array) => {
5555
const array = decode(data) as Array<any>;
5656
return new Set(array);
5757
},
@@ -60,14 +60,14 @@ describe("ExtensionCodec", () => {
6060
// Map<T>
6161
extensionCodec.register({
6262
type: 1,
63-
encode: (object: unknown) => {
63+
encode: (object: unknown): Uint8Array | null => {
6464
if (object instanceof Map) {
6565
return encode([...object]);
6666
} else {
6767
return null;
6868
}
6969
},
70-
decode: (data) => {
70+
decode: (data: Uint8Array) => {
7171
const array = decode(data) as Array<[unknown, unknown]>;
7272
return new Map(array);
7373
},

0 commit comments

Comments
 (0)