This is an automated email from the ASF dual-hosted git repository.

wangweipeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-fury.git


The following commit(s) were added to refs/heads/main by this push:
     new 25d45146 feat(JavaScript): create zero-copy buffer when convert (#1386)
25d45146 is described below

commit 25d451461ed904b8b0110cb8f408e404499f10d0
Author: 野声 <[email protected]>
AuthorDate: Tue Feb 27 18:21:33 2024 +0800

    feat(JavaScript): create zero-copy buffer when convert (#1386)
---
 javascript/packages/fury/lib/fury.ts           | 3 ++-
 javascript/packages/fury/lib/platformBuffer.ts | 4 +++-
 javascript/packages/fury/lib/reader/index.ts   | 2 +-
 javascript/packages/fury/package.json          | 2 +-
 4 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/javascript/packages/fury/lib/fury.ts 
b/javascript/packages/fury/lib/fury.ts
index 1ea7d26c..aa53e13a 100644
--- a/javascript/packages/fury/lib/fury.ts
+++ b/javascript/packages/fury/lib/fury.ts
@@ -78,11 +78,12 @@ export default class {
     if (!isCrossLanguage) {
       throw new Error("support crosslanguage mode only");
     }
-    this.binaryReader.uint8(); // skip language
     const isOutOfBandEnabled = (bitmap & ConfigFlags.isOutOfBandFlag) === 
ConfigFlags.isOutOfBandFlag;
     if (isOutOfBandEnabled) {
       throw new Error("outofband mode is not supported now");
     }
+
+    this.binaryReader.uint8(); // skip language
     this.binaryReader.int32(); // native object offset. should skip.  
javascript support cross mode only
     this.binaryReader.int32(); // native object size. should skip.
     return serializer.read();
diff --git a/javascript/packages/fury/lib/platformBuffer.ts 
b/javascript/packages/fury/lib/platformBuffer.ts
index fb95f456..b28df55b 100644
--- a/javascript/packages/fury/lib/platformBuffer.ts
+++ b/javascript/packages/fury/lib/platformBuffer.ts
@@ -140,7 +140,9 @@ export class BrowserBuffer extends Uint8Array implements 
PlatformBuffer {
 export const fromUint8Array = hasBuffer
   ? (ab: Buffer | Uint8Array) => {
       if (!Buffer.isBuffer(ab)) {
-        return (Buffer.from(ab) as unknown as PlatformBuffer);
+        // 
https://nodejs.org/docs/latest/api/buffer.html#static-method-bufferfromarraybuffer-byteoffset-length
+        // Create a zero-copy Buffer wrapper around the ArrayBuffer pointed to 
by the Uint8Array
+        return (Buffer.from(ab.buffer, ab.byteOffset, ab.byteLength) as 
unknown as PlatformBuffer);
       } else {
         return ab as unknown as PlatformBuffer;
       }
diff --git a/javascript/packages/fury/lib/reader/index.ts 
b/javascript/packages/fury/lib/reader/index.ts
index ef308e79..e0df6000 100644
--- a/javascript/packages/fury/lib/reader/index.ts
+++ b/javascript/packages/fury/lib/reader/index.ts
@@ -35,7 +35,7 @@ export const BinaryReader = (config: Config) => {
   function reset(ab: Uint8Array) {
     buffer = fromUint8Array(ab);
     byteLength = buffer.byteLength;
-    dataView = new DataView(buffer.buffer, buffer.byteOffset);
+    dataView = new DataView(buffer.buffer, buffer.byteOffset, byteLength);
     if (sliceStringEnable) {
       bigString = buffer.toString("latin1", 0, byteLength);
     }
diff --git a/javascript/packages/fury/package.json 
b/javascript/packages/fury/package.json
index 92af2bc3..c0b79053 100644
--- a/javascript/packages/fury/package.json
+++ b/javascript/packages/fury/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@furyjs/fury",
-  "version": "0.5.8-beta",
+  "version": "0.5.9-beta",
   "description": "A blazing fast multi-language serialization framework 
powered by jit and zero-copy",
   "main": "dist/index.js",
   "scripts": {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to