gpt4 book ai didi

java - 这 13 个字节长多少?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:52:01 25 4
gpt4 key购买 nike

两个引号:

All of the remaining messages in the protocol take the form of <length prefix><message ID><payload>. The length prefix is a four byte big-endian value. The message ID is a single decimal byte. The payload is message dependent.

request: <len=0013><id=6><index><begin><length> 

The request message is fixed length, and is used to request a block. The payload contains the following information:

  • index: integer specifying the zero-based piece index
  • begin: integer specifying the zero-based byte offset within the piece
  • length: integer specifying the requested length.

当我写下所有内容时,它总计为 5 个字节。使用

ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
byteStream.write( 13 );
byteStream.write( 6 );
byteStream.write( index );
byteStream.write( begin );
byteStream.write( length );

message = byteStream.toByteArray();

编辑:抱歉,我写的时候有点生气。它的比特流协议(protocol)。使用这个 spec .

最佳答案

write() 方法写入一个字节。

如果您向它发送一个 char 或 int,它只会用 & 0xFF 去除第 8 位以上的所有内容。

DataOutputStream(writeInt、writeShort 等)有更多选项,但它使用大端字节顺序,因此您可能需要在将值传递给之前执行 Integer.reverseBytes()(或 Short.reverseBytes())调用writeXYZ() 方法。

ByteArrayOutputStream byteStream = new ByteArrayOutputStream();

DataOutputStream dout = new DataOutputStream(byteStream);

dout.writeInt( 0x13 ); // L:4
dout.write( 6 ); // L:5
dout.writeShort( index ); // guess, L:7
dout.writeLong( begin ); // >4GB support? L:15
dout.writeInt( length ); // clients accept below to 2^17, L:19

dout.flush(); // to be sure

message = byteStream.toByteArray();

备注:规范没有规定indexbeginlength的长度。我只是想提供一个可用选项的示例。

编辑 2:根据 D.Shawley 的回答和找到的规范编辑样本 here .

关于java - 这 13 个字节长多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1046312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com