@@ -187,6 +187,22 @@ class ZVal : public NonAssignable {
187187 }
188188 }
189189 };
190+ class Buf : public Str {
191+ public:
192+ Buf (const char *data, std::size_t length) : Str(data, length) { }
193+ virtual v8::Local<v8::Value> ToJs (ObjectMapper *m) const {
194+ Nan::EscapableHandleScope scope;
195+ return scope.Escape (Nan::CopyBuffer (data_, length_).ToLocalChecked ());
196+ }
197+ };
198+ class OBuf : public OStr {
199+ public:
200+ OBuf (const char *data, std::size_t length) : OStr(data, length) { }
201+ virtual v8::Local<v8::Value> ToJs (ObjectMapper *m) const {
202+ Nan::EscapableHandleScope scope;
203+ return scope.Escape (Nan::CopyBuffer (data_, length_).ToLocalChecked ());
204+ }
205+ };
190206 class Obj : public Base {
191207 objid_t id_;
192208 public:
@@ -252,6 +268,9 @@ class ZVal : public NonAssignable {
252268 SetOwnedString (*str, str.length ());
253269 return ;
254270 }
271+ } else if (node::Buffer::HasInstance (v)) {
272+ SetOwnedBuffer (node::Buffer::Data (v), node::Buffer::Length (v));
273+ return ;
255274 } else if (v->IsObject ()) {
256275 SetJsObject (m, Nan::To<v8::Object>(v).ToLocalChecked ());
257276 return ;
@@ -329,6 +348,16 @@ class ZVal : public NonAssignable {
329348 type_ = VALUE_OSTR;
330349 new (&ostr_) OStr (data, length);
331350 }
351+ void SetBuffer (const char *data, std::size_t length) {
352+ PerhapsDestroy ();
353+ type_ = VALUE_BUF;
354+ new (&buf_) Buf (data, length);
355+ }
356+ void SetOwnedBuffer (const char *data, std::size_t length) {
357+ PerhapsDestroy ();
358+ type_ = VALUE_OBUF;
359+ new (&obuf_) OBuf (data, length);
360+ }
332361 void SetJsObject (ObjectMapper *m, v8::Local<v8::Object> o) {
333362 SetJsObject (m->IdForJsObj (o));
334363 }
@@ -380,11 +409,13 @@ class ZVal : public NonAssignable {
380409 }
381410 enum ValueTypes {
382411 VALUE_EMPTY, VALUE_NULL, VALUE_BOOL, VALUE_INT, VALUE_DOUBLE,
383- VALUE_STR, VALUE_OSTR, VALUE_JSOBJ, VALUE_PHPOBJ
412+ VALUE_STR, VALUE_OSTR, VALUE_BUF, VALUE_OBUF,
413+ VALUE_JSOBJ, VALUE_PHPOBJ
384414 } type_;
385415 union {
386416 int empty_; Null null_; Bool bool_; Int int_; Double double_;
387- Str str_; OStr ostr_; JsObj jsobj_; PhpObj phpobj_;
417+ Str str_; OStr ostr_; Buf buf_; OBuf obuf_;
418+ JsObj jsobj_; PhpObj phpobj_;
388419 };
389420 const Base &AsBase () {
390421 switch (type_) {
@@ -402,6 +433,10 @@ class ZVal : public NonAssignable {
402433 return str_;
403434 case VALUE_OSTR:
404435 return ostr_;
436+ case VALUE_BUF:
437+ return buf_;
438+ case VALUE_OBUF:
439+ return obuf_;
405440 case VALUE_JSOBJ:
406441 return jsobj_;
407442 case VALUE_PHPOBJ:
0 commit comments