From e1644b671dd5ead46cc64b4a03db056efcbdd49e Mon Sep 17 00:00:00 2001 From: bmcq-0 <66541602+bmcq-0@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:48:51 -0500 Subject: [PATCH] Update function-buffer-varints.md --- docs/function-buffer-varints.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/function-buffer-varints.md b/docs/function-buffer-varints.md index 1bd4932..20c24ad 100644 --- a/docs/function-buffer-varints.md +++ b/docs/function-buffer-varints.md @@ -50,15 +50,17 @@ The functions above are inefficient and difficult to understand compared to a li The `buffer` library will receive 4 new functions: ``` -buffer.readleb128(b: buffer, offset: number): number -buffer.readuleb128(b: buffer, offset: number): number +buffer.readleb128(b: buffer, offset: number): (number, number) +buffer.readuleb128(b: buffer, offset: number): (number, number) -buffer.writeleb128(b: buffer, offset: number, value: number): () -buffer.writeuleb128(b: buffer, offset: number, value: number): () +buffer.writeleb128(b: buffer, offset: number, value: number): number +buffer.writeuleb128(b: buffer, offset: number, value: number): number ``` Since other numbers in the buffer library have unsigned and signed implementations, it also makes sense to include both options for varints. +The functions take arguments similar to other read/write functions in the buffer library. However, they differ in that they return the amount of bytes that were read/written. In readleb128/readuleb128, this is the second return value. Having these functions return the count is necessary as it must be known in order for users to keep track of the buffer offset. + ## Drawbacks The only drawback known is a marginal increase in library complexity. However, the performance benefit from having library implementations of these functions outweighs the negligible change in complexity and is not a serious concern.