Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Represent (u)int64 fields with Buffers #16

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions protobuf_for_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ using google::protobuf::MethodDescriptor;
using google::protobuf::Reflection;
using google::protobuf::Service;
using google::protobuf::ServiceDescriptor;
using google::protobuf::int64;
using google::protobuf::uint64;

using node::ObjectWrap;
using node::Buffer;
Expand Down Expand Up @@ -203,10 +205,14 @@ namespace protobuf_for_node {
return Integer::New(GET(Int32));
case FieldDescriptor::CPPTYPE_UINT32:
return Integer::NewFromUnsigned(GET(UInt32));
case FieldDescriptor::CPPTYPE_INT64:
return Number::New(GET(Int64));
case FieldDescriptor::CPPTYPE_UINT64:
return Number::New(GET(UInt64));
case FieldDescriptor::CPPTYPE_INT64: {
int64 value = GET(Int64);
return Buffer::New((char *)&value, sizeof(value))->handle_;
}
case FieldDescriptor::CPPTYPE_UINT64: {
uint64 value = GET(UInt64);
return Buffer::New((char *)&value, sizeof(value))->handle_;
}
case FieldDescriptor::CPPTYPE_FLOAT:
return Number::New(GET(Float));
case FieldDescriptor::CPPTYPE_DOUBLE:
Expand Down Expand Up @@ -316,10 +322,18 @@ namespace protobuf_for_node {
SET(UInt32, value->Uint32Value());
break;
case FieldDescriptor::CPPTYPE_INT64:
SET(Int64, value->NumberValue());
if (Buffer::HasInstance(value)) {
SET(Int64, *(int64 *)Buffer::Data(value->ToObject()));
} else {
SET(Int64, value->NumberValue());
}
break;
case FieldDescriptor::CPPTYPE_UINT64:
SET(UInt64, value->NumberValue());
if (Buffer::HasInstance(value)) {
SET(UInt64, *(uint64 *)Buffer::Data(value->ToObject()));
} else {
SET(UInt64, value->NumberValue());
}
break;
case FieldDescriptor::CPPTYPE_FLOAT:
SET(Float, value->NumberValue());
Expand Down