How does nodejs ref-struct turn into Buffer?

  node.js, question

Nodejs needs to send structure data to C process through socket, using:
https://www.npmjs.com/package …

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,
 state:  ref.types.int
 })
 
 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.write(head);
 });
 
 client.on('data', function(data) {
 console.log(data.toString());
 client.end();
 });
 
 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)