Skip to content

Commit

Permalink
chore: docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Nov 25, 2024
1 parent 8c132b8 commit 8618e64
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ On the client:
socket.on('player-data', (buffer) => {
// create a view over the buffer
const view = new DataView(buffer);
// pass the view to the decoder
const decoded = playerSchema.decode(view);
// the decoder returns the number of bytes read and the value
console.log(decoded); // {read: 22, value: {...}}
const player = decoded.value;
// or if you're feeling elegant,
const {value: player} = playerSchema.decode(new DataView(buffer));
}
// pass the view to the decoder to get the value
const player = playerSchema.decode(view);
});
```

In this example, the size of payload is only **22 bytes**. `JSON.stringify` would consume **124 bytes**.
Expand Down Expand Up @@ -160,8 +155,9 @@ class YourCodec {
decode(view: DataView, target: {byteOffset: number}): any

// return the number of bytes written
encode(value: any, view: DataView, byteOffset): number
encode(value: any, view: DataView, byteOffset: number): number

// get the encoded size of a value
size(value: any): number

}
Expand Down

0 comments on commit 8618e64

Please sign in to comment.