You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by GitBox <gi...@apache.org> on 2021/12/13 08:03:04 UTC

[GitHub] [thrift] Jens-G commented on a change in pull request #2483: Enhance TFramedTransport performance for nodejs

Jens-G commented on a change in pull request #2483:
URL: https://github.com/apache/thrift/pull/2483#discussion_r767484788



##########
File path: lib/nodejs/lib/thrift/framed_transport.js
##########
@@ -34,36 +34,31 @@ function TFramedTransport(buffer, callback) {
 TFramedTransport.prototype = new THeaderTransport();
 
 TFramedTransport.receiver = function(callback, seqid) {
-  var residual = null;
-
+  var residual = [];
+  
   return function(data) {
-    // Prepend any residual data from our previous read
-    if (residual) {
-      data = Buffer.concat([residual, data]);
-      residual = null;
+    // push received data to residual
+    for(var i = 0; i < data.length; ++i) {
+      residual.push(data[i])
     }
 
-    // framed transport
-    while (data.length) {
-      if (data.length < 4) {
-        // Not enough bytes to continue, save and resume on next packet
-        residual = data;
+    while (residual.length > 0) {      
+      if (residual.length < 4) {
+		// Not enough bytes to continue, save and resume on next packet
         return;
       }
-      var frameSize = binary.readI32(data, 0);
-      if (data.length < 4 + frameSize) {
-        // Not enough bytes to continue, save and resume on next packet
-        residual = data;
+      // get single package sieze
+      var frameSize = binary.readI32(Buffer.from(residual.slice(0, 4)), 0);
+      // Not enough bytes to continue, save and resume on next packet
+      if (residual.length < 4 + frameSize) {
         return;
       }
 
-      var frame = data.slice(4, 4 + frameSize);
-      residual = data.slice(4 + frameSize);
-
+      // splice first 4 bytes
+      residual.splice(0, 4)
+      // get package data
+      var frame = Buffer.from(residual.splice(0, frameSize));      
       callback(new TFramedTransport(frame), seqid);
-
-      data = residual;
-      residual = null;
     }

Review comment:
       What happened to "data"?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org