From 8618e64abaa90e2c9f19185ce51483095fc50047 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 25 Nov 2024 17:04:00 -0600 Subject: [PATCH] chore: docs --- README.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 430ec30..2536fc7 100644 --- a/README.md +++ b/README.md @@ -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**. @@ -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 }