How does nodejs ref-struct turn into Buffer?

  node.js, question

Nodejs needs to send structure data to C process through socket, using: …

But when sending error, or only recognize Buffer:

var net = require('net');
 var ref = require('ref')
 var StructType = require('ref-struct')
 var MyDataHead = StructType({
 type: ref.types.uint,
 len: ref.types.uint,
 var head = new MyDataHead
 head.type = 1
 head.len = 0
 head.state = 0
 var sockfile = '/var/run/xxx.sock'
 var client = net.connect({path: sockfile}, function() {
 //'connect' listener
 console.log('connected to server!'  );
 client.on('data', function(data) {
 client.on('end', function() {
 console.log('disconnected from server');

TypeError: Invalid data, chunk must be a string or buffer, not object

Change to var head = ref.alloc(MyDataHead)