Ejemplo n.º 1
0
Handle<Value> Protobuf::New(const Arguments& args) {
	HandleScope scope;

	Local<Object> buffer_obj = args[0]->ToObject();
	char *buffer_data = Buffer::Data(buffer_obj);
	size_t buffer_length = Buffer::Length(buffer_obj);

	FileDescriptorSet descriptors;
	if (!descriptors.ParseFromArray(buffer_data, buffer_length)) {
		return v8::ThrowException(
			v8::Exception::Error(String::New("Malformed descriptor")));
	}

	DescriptorPool* pool = new DescriptorPool;
	for (int i = 0; i < descriptors.file_size(); i++)
		pool->BuildFile(descriptors.file(i));

	Protobuf* obj = new Protobuf(pool);
	args.This()->SetInternalField(1, Array::New());

	obj->Wrap(args.This());

	return args.This();
}