Your code is very elegant and it reads like C code. I may borrow from it. I keep forgetting a buffer can be treated like an array with '[]' indexing.
I wanted frames to be able to scale from (the more common) small 10s and 100s of bytes to gigabytes. That's why I spent so much time and code on being able to treat frames as streams. One of my problems as a coder is I puke out gobs of code (over?) generalizing my design. :) -LLeo. On Tuesday, July 24, 2012 11:51:09 AM UTC-4, Tim Caswell wrote: > > Thanks for sharing the module. I use a similar technique for sending > msgpack encoded messages over plain sockets in smith. > https://github.com/c9/smith/blob/master/smith.js#L149-190 > > On Fri, Jul 20, 2012 at 9:44 PM, LLeo <[email protected]> wrote: > > I have worked up my first serious npm module. It is a framing protocol > for > > straight socket communications. > > > > Rather that separating messages by some identifier (usually a newline), > my > > framing protocol writes a simple 32bit unsigned integer in network order > > (big-endian) indicating the length of the message, then message is sent. > > This is simple at first, but it gets complicated quickly. > > > > The constructor is simple `var frap = new Frap(socket)` > > > > Using this module you can send and receive a message either as a single > > Buffer or series of Buffers. Single buffers are sent and received as > > frap.write(buf) and > > frap.on('data', function(buf){...}). A collection of buffers can be sent > and > > received as a single message (aka "frame") with frap.sendFrame(buf0, > ..., > > bufN) and frap.on('frame', function(bufs){...} . Thats the easy part. > > > > You can also receive frames as a Readable Stream with frap.on('header', > > function(rstream, framelen){...}). And you can send frames as a writable > > stream with `wstream = frap.createWriteStream(framelen)`. > > > > I spent a good amount of effort working on efficientcy in space and > time. > > Frap supports a customized pipe() that passes buffers at the frame and > > sub-frame level. > > > > The real utility of this module is for sending large binary blobs > between > > node instances. And given how simple the framing protocol is it would be > > relatively easy to implement in any other language. > > > > > > I hope this is useful, > > -LLeo. > > > > PS. this is my first posting and I am using the web interface. I hope > the > > formatting doesn't suck. > > > > -- > > 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 > -- 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
