Skip to content

Commit

Permalink
Rework to use buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
mdave committed Jan 6, 2016
1 parent 016059c commit 9a555cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
17 changes: 4 additions & 13 deletions src/openzwave-values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,10 @@ namespace OZW {
break;
}
case OpenZWave::ValueID::ValueType_Raw: {
checkType(info[validx]->IsArray());
Local<Array> val = Local<Array>::Cast(info[validx]);
uint8 len = val->Length();
uint8 *valArr = new uint8[len];

for (uint8 i = 0; i < len; i++) {
Local<Object> idx = Local<Object>::Cast(val->Get(i));
if (!idx->IsNumber())
Nan::ThrowTypeError("Raw value array contains a non-integer");
valArr[i] = (uint8)idx->ToInteger()->Value();
}
OpenZWave::Manager::Get()->SetValue(*vit, valArr, len);
delete [] valArr;
checkType(Buffer::HasInstance(info[validx]));
uint8 *val = (uint8*)Buffer::Data(info[validx]);
uint8 len = Buffer::Length(info[validx]);
OpenZWave::Manager::Get()->SetValue(*vit, val, len);
break;
}
}
Expand Down
11 changes: 2 additions & 9 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,11 @@ namespace OZW {
case OpenZWave::ValueID::ValueType_Raw: {
uint8 *val, len;
OpenZWave::Manager::Get()->GetValueAsRaw(value, &val, &len);

// Copy raw values into array.
Local<Array> rawval = Nan::New<Array>(len);
for (int i = 0; i < len; i++) {
rawval->Set(Nan::New<Integer>(i), Nan::New<Integer>(val[i]));
}
delete [] val;

Nan::Set(valobj,
Nan::New<String>("value").ToLocalChecked(),
rawval
Nan::CopyBuffer((char *)val, len).ToLocalChecked()
);
delete [] val;
break;
}
default: {
Expand Down

0 comments on commit 9a555cf

Please sign in to comment.