我写了一个 node/ssjs 程序,它可以:
- 使用 TLS 模块与数据服务器 (Apache MIMA) 进行 TCP 连接。 (好的)
- 通过 protobuffer 模块对消息进行编码/解码(序列化/反序列化)..(OK)
- 将序列化消息发送到服务器并获取响应。 (不好)。
服务器的手动类型:
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 (e.g. 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 (e.g. 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
我的问题是:
- 如何获取protobuf的4字节长度?
- 如何连接
发送之前的那些缓冲区?
- 如何发送?
- 是否可以做
JavaScript?观察:服务器使用 Little Endian 字节顺序,
客户端也是如此。
谢谢你们...
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)