From 9a555cf376a606f543e4b55bfc20d9bfec1441e3 Mon Sep 17 00:00:00 2001 From: mdave Date: Wed, 6 Jan 2016 18:55:11 +0000 Subject: [PATCH] Rework to use buffers --- src/openzwave-values.cc | 17 ++++------------- src/utils.cc | 11 ++--------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/openzwave-values.cc b/src/openzwave-values.cc index 5aba1f3d..0166fe01 100644 --- a/src/openzwave-values.cc +++ b/src/openzwave-values.cc @@ -88,19 +88,10 @@ namespace OZW { break; } case OpenZWave::ValueID::ValueType_Raw: { - checkType(info[validx]->IsArray()); - Local val = Local::Cast(info[validx]); - uint8 len = val->Length(); - uint8 *valArr = new uint8[len]; - - for (uint8 i = 0; i < len; i++) { - Local idx = Local::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; } } diff --git a/src/utils.cc b/src/utils.cc index ee23a780..6ddf54ab 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -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 rawval = Nan::New(len); - for (int i = 0; i < len; i++) { - rawval->Set(Nan::New(i), Nan::New(val[i])); - } - delete [] val; - Nan::Set(valobj, Nan::New("value").ToLocalChecked(), - rawval + Nan::CopyBuffer((char *)val, len).ToLocalChecked() ); + delete [] val; break; } default: {