Skip to content

Commit ecffaaa

Browse files
Update README.md to add encode method documentation.
1 parent ed0fbb5 commit ecffaaa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ Parse a `Buffer`/`Uint8Array` object `buffer` with this parser and return the
9595
resulting object. When `parse(buffer)` is called for the first time, the
9696
associated parser code is compiled on-the-fly and internally cached.
9797

98+
### encode(object)
99+
Encode an object `object` with this parser and return the resulting buffer.
100+
101+
```typescript
102+
const parser = new Parser()
103+
.int8('age')
104+
.string('name', { zeroTerminated: true });
105+
106+
const buffer = parser.encode({
107+
age: 25,
108+
name: 'John'
109+
});
110+
111+
// Results in: <Buffer 19 4a 6f 68 6e 00>
112+
```
113+
98114
### create(constructorFunction)
99115
Set the constructor function that should be called to create the object
100116
returned from the `parse` method.

0 commit comments

Comments
 (0)