Reverse engineered prompt

GitHub

Build me a small Node.js module for fast request and response messaging over any duplex stream, especially TCP sockets. I want it to feel really simple to use. You should be able to create a wrapper stream, send a message with an optional callback if you want a reply, listen for incoming messages and answer them with a reply callback, and allow multiple requests to be in flight at once so they get pipelined instead of waiting on each other.

Use a compact binary format with a tiny header that includes the message type, a message id, and the body length so parsing is quick. Default payloads should work as raw buffers, but please also support optional utf8 and JSON encoding modes. Add ping support so a client can check whether the connection is still alive, and a destroy method that closes things cleanly and fails any pending callbacks.

Please include a basic echo server and client example using Node net sockets, plus tests for replies, errors, fire and forget messages, pipelining, ping, and cleanup. Look up current stream docs online if you need to.

Have a live product UI? Try website reverse