Node.js,protobuffer,buffer.lentgh ..如何发送结构化的缓冲区/消息槽tcp?

我写了一个节点/ ssjs程序,使:

  • Tcp连接到数据服务器(Apache MIMA),使用TLS模块。 (好)
  • 通过protobuffer模块对消息进行编码/解码(序列化/反序列化)。(OK)
  • 将序列化的消息发送到服务器并获得响应。 (不好)。

服务器的手册types:

Structure of message: [ Length | Header length | Header (| Body length |Body) ] Length – message length = fixed size (4 bytes). Note that this is only the size of following message (not the prefix itself); Header length – fixed size (4 bytes); Header – contains message metadata (eg messageId); Body length – fixed size (4 bytes, optional). If body is not required, body size is not serialized. In such case, message is 4 (message length) + 4 (header length) + length(header) bytes long. Body – the message payload (optional). If body is not present (eg response notification without data) it is not serialized. Length [bytes] Content 4 Whole message length 4 Header message length (H_LEN) H_LEN Protocol Buffers encoded MessageHeaderProto 4 Body message length (B_LEN), optional B_LEN Protocol Buffers encoded Message 

我的问题是:

  • 如何获得protobuffer的4字节长度?
  • 如何在发送之前连接这些缓冲区?
  • 如何发送?
  • 是否有可能使用JavaScript? 观察:服务器也使用Little Endian字节顺序,客户端。

谢谢你们…