Switched extension to return faster sliceable Buffers

pull/300/head
murgatroid99 10 years ago
parent c4e09f667b
commit 7bd3250c2a
  1. 22
      src/node/ext/byte_buffer.cc
  2. 4
      src/node/ext/byte_buffer.h
  3. 3
      src/node/ext/event.cc
  4. 1
      src/node/interop/interop_client.js

@ -39,13 +39,17 @@
#include "grpc/grpc.h"
#include "grpc/support/slice.h"
#include "byte_buffer.h"
namespace grpc {
namespace node {
#include "byte_buffer.h"
using ::node::Buffer;
using v8::Context;
using v8::Function;
using v8::Handle;
using v8::Object;
using v8::Number;
using v8::Value;
grpc_byte_buffer *BufferToByteBuffer(Handle<Value> buffer) {
@ -73,7 +77,19 @@ Handle<Value> ByteBufferToBuffer(grpc_byte_buffer *buffer) {
memcpy(result + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next));
offset += GPR_SLICE_LENGTH(next);
}
return NanEscapeScope(NanNewBufferHandle(result, length));
return NanEscapeScope(MakeFastBuffer(NanNewBufferHandle(result, length)));
}
Handle<Value> MakeFastBuffer(Handle<Value> slowBuffer) {
NanEscapableScope();
Handle<Object> globalObj = Context::GetCurrent()->Global();
Handle<Function> bufferConstructor = Handle<Function>::Cast(
globalObj->Get(NanNew("Buffer")));
Handle<Value> consArgs[3] = { slowBuffer,
NanNew<Number>(Buffer::Length(slowBuffer)),
NanNew<Number>(0) };
Handle<Object> fastBuffer = bufferConstructor->NewInstance(3, consArgs);
return NanEscapeScope(fastBuffer);
}
} // namespace node
} // namespace grpc

@ -50,6 +50,10 @@ grpc_byte_buffer *BufferToByteBuffer(v8::Handle<v8::Value> buffer);
/* Convert a grpc_byte_buffer to a Node.js Buffer */
v8::Handle<v8::Value> ByteBufferToBuffer(grpc_byte_buffer *buffer);
/* Convert a ::node::Buffer to a fast Buffer, as defined in the Node
Buffer documentation */
v8::Handle<v8::Value> MakeFastBuffer(v8::Handle<v8::Value> slowBuffer);
} // namespace node
} // namespace grpc

@ -80,7 +80,8 @@ Handle<Value> ParseMetadata(grpc_metadata *metadata_elements, size_t length) {
metadata_object->Set(key_string, array);
}
array->Set(index_map[elem->key],
NanNewBufferHandle(elem->value, elem->value_length));
MakeFastBuffer(
NanNewBufferHandle(elem->value, elem->value_length)));
index_map[elem->key] += 1;
}
return NanEscapeScope(metadata_object);

@ -178,6 +178,7 @@ function pingPong(client, done) {
payload: {body: zeroBuffer(payload_sizes[index])}
});
call.on('data', function(response) {
debugger;
assert.strictEqual(response.payload.type,
testProto.PayloadType.COMPRESSABLE);
assert.equal(response.payload.body.limit - response.payload.body.offset,

Loading…
Cancel
Save