my first module for node.
https://github.com/freedaxin/head_body_buffers

Overview

When transfer packets in network composed of a fixed length "head" and a 
variable length "body", the "data" event emitted by node socket probably 
not a complete packet, but part of several packets. This tool help you get 
the "head" and "body" from the buffers.

If the "body" is in a single buffer, data will not be copyed to a new 
buffer, just use buffer.slice() to reference data.

see the test for usage.
<https://github.com/freedaxin/head_body_buffers#install>Install

npm install head_body_buffers
<https://github.com/freedaxin/head_body_buffers#example>Example

var net = require('net');var HeadBodyBuffers = 
require('head_body_buffers').HeadBodyBuffers;
function packetLength(data) {
    var len = data[0];
    len += (data[1] << 8);
    len += (data[2] << 16);
    return len;}
var hbd = new HeadBodyBuffers(4, packetLength);hbd.on('packet', function (head, 
body) {
    console.log("head:", head, head.length);
    console.log("body:", body, body.length);});
var client = net.connect(3306);client.on('data', function(data) {
  hbd.addBuffer(data);});

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to