Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"sources": [
"src/crc-64-jones.c",
"src/Crc64.cc"
]
],
"include_dirs": [
"<!(node -e \"require('nan')\")"
],
}
]
}
2 changes: 1 addition & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Transform = require('stream').Transform,
lzf = require('lzf'),
util = require('util'),
bufferEqual = require('buffer-equal'),
Int64 = require('int64-native'),
Int64 = require('int64-native-node12'),
Crc64 = require('../build/Release/Crc64.node').Crc64;

exports = module.exports = Parser;
Expand Down
2 changes: 1 addition & 1 deletion lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
var Transform = require('stream').Transform,
lzf = require('lzf'),
util = require('util'),
Int64 = require('int64-native'),
Int64 = require('int64-native-node12'),
Crc64 = require('../build/Release/Crc64.node').Crc64;

exports = module.exports = Writer;
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rdb-tools",
"version": "0.1.1",
"version": "0.1.2",
"description": "Redis RDB parsing, filtering and creating tools",
"author": "Danny Yates <danny@codeaholics.org>",
"licenses": [
Expand All @@ -22,10 +22,11 @@
"Parser"
],
"dependencies": {
"stream-parser": "~0.1.0",
"lzf": "~0.1.3",
"int64-native": "~0.2.0",
"buffer-equal": "0.0.0"
"buffer-equal": "0.0.0",
"int64-native-node12": "^0.4.0",
"lzf": "git+https://github.com/kieut/node-lzf.git",
"nan": "^1.8.4",
"stream-parser": "~0.1.0"
},
"devDependencies": {
"mocha": "~1.11.0",
Expand Down
111 changes: 62 additions & 49 deletions src/Crc64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,75 +12,88 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <node.h>
#include <v8.h>
#include <node_buffer.h>

#include "Crc64.h"
#include "nan.h"

using namespace v8;
using namespace node;


extern "C"
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);

void Crc64::Init(Handle<Object> exports) {
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);

tpl->SetClassName(String::NewSymbol("Crc64"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->PrototypeTemplate()->Set(String::NewSymbol("push"), FunctionTemplate::New(Push)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("value"), FunctionTemplate::New(GetValue)->GetFunction());
class Crc64 : public ObjectWrap {

Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
exports->Set(String::NewSymbol("Crc64"), constructor);
}
public:

Crc64::Crc64() {
crc = 0;
}
static void Init(Handle<Object> exports) {
NanScope();
Local<FunctionTemplate> tmpl = NanNew<FunctionTemplate>(Crc64::New);

tmpl->SetClassName(NanNew("Crc64"));
tmpl->InstanceTemplate()->SetInternalFieldCount(1);

Crc64::~Crc64() {}
NODE_SET_PROTOTYPE_METHOD(tmpl, "push", Push);
NODE_SET_PROTOTYPE_METHOD(tmpl, "value", GetValue);

Handle<Value> Crc64::New(const Arguments& args) {
if (args.Length() != 0) {
return ThrowException(Exception::Error(String::New("Unexpected arguments")));
}
NanAssignPersistent(functionTemplate, tmpl);
NanAssignPersistent(constructor, tmpl->GetFunction());
exports->Set(NanNew("Crc64"), tmpl->GetFunction());
}

private:

Crc64() {
crc = 0;
}

HandleScope scope;
Crc64* obj = new Crc64();
obj->Wrap(args.This());
return args.This();
}
~Crc64() {
}

Handle<Value> Crc64::Push(const Arguments& args) {
if (args.Length() != 1 || !Buffer::HasInstance(args[0])) {
return ThrowException(Exception::Error(String::New("Expecting a single Buffer argument")));
}
static NAN_METHOD(New) {
NanScope();
Crc64* instance = new Crc64();
instance->Wrap(args.This());
NanReturnThis();
}

HandleScope scope;
Crc64* obj = ObjectWrap::Unwrap<Crc64>(args.This());
static NAN_METHOD(Push) {
NanScope();
if (args.Length() != 1 || !Buffer::HasInstance(args[0]))
return NanThrowError("Expecting a single Buffer argument");

Crc64* instance = ObjectWrap::Unwrap<Crc64>(args.Holder());
Local<Object> bytes = args[0]->ToObject();
instance->crc = crc64(instance->crc, (unsigned char *)Buffer::Data(bytes), Buffer::Length(bytes));
NanReturnUndefined();
}

obj->crc = crc64(obj->crc, (unsigned char *)Buffer::Data(bytes), Buffer::Length(bytes));
static NAN_METHOD(GetValue) {
NanScope();
if (args.Length() != 0)
return NanThrowError("Unexpected arguments");

return Undefined();
}
Crc64* instance = ObjectWrap::Unwrap<Crc64>(args.Holder());
Local<Object> BufferOut = NanNewBufferHandle((char*)&(instance->crc), sizeof(uint64_t));
NanReturnValue(BufferOut);
}

Handle<Value> Crc64::GetValue(const Arguments& args) {
if (args.Length() != 0) {
return ThrowException(Exception::Error(String::New("Unexpected arguments")));
}
static Persistent<FunctionTemplate> functionTemplate;
static Persistent<Function> constructor;

HandleScope scope;
Crc64* obj = ObjectWrap::Unwrap<Crc64>(args.This());
Buffer* BufferOut = Buffer::New((char*)&(obj->crc), sizeof(uint64_t));
return scope.Close(BufferOut->handle_);
}
uint64_t crc;
};

extern "C"
void init(Handle<Object> exports) {

Persistent<FunctionTemplate> Crc64::functionTemplate;
Persistent<Function> Crc64::constructor;


extern "C" {

static void init(Handle<Object> exports) {
Crc64::Init(exports);
}
}

NODE_MODULE(Crc64, init)
NODE_MODULE(Crc64, init)
};
39 changes: 0 additions & 39 deletions src/Crc64.h

This file was deleted.