本文整理汇总了Java中io.netty.buffer.ByteBuf.writeMedium方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.writeMedium方法的具体用法?Java ByteBuf.writeMedium怎么用?Java ByteBuf.writeMedium使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.writeMedium方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext context, ServerMessage message, ByteBuf out) throws Exception {
message.encode(stream);
header.id = message.id;
header.decrypted = stream.getBuffer();
stream.reset(true);
crypto.encryptPacket(header);
out.writeShort(message.id);
out.writeMedium(header.payload.length);
out.writeShort((short)5);
out.writeBytes(header.payload);
}
示例2: shakeHands
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public void shakeHands(int revision) throws IOException {
// 15 = JS5 header
writer.write((byte) 15);
writer.write(revision);
writer.flush();
int response = reader.readByte();
if (response != HANDSHAKE_SUCCESS) {
if (response == HANDSHAKE_OUTDATED) {
throw new IllegalStateException("Handshake failed, wrong revision specified");
}
throw new IllegalStateException("Handshake failed, unknown error encountered");
}
ByteBuf buffer = Unpooled.buffer(4);
// Login state
// 2 = In-game
// 3 = Not in-game
buffer.writeByte(3);
// Padding
buffer.writeMedium(0);
writer.write(buffer);
writer.flush();
}
示例3: downloadFile
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private FileResult downloadFile(int indexId, int fileId, boolean shouldDecompress)
throws IOException {
ByteBuf buffer = Unpooled.buffer(4);
// Type
buffer.writeByte(indexId == 255 ? 1 : 0);
// Hash
buffer.writeMedium(indexId << 16 | fileId);
writer.write(buffer);
writer.flush();
int remoteIndexId = reader.readUnsignedByte();
if (indexId != remoteIndexId) {
throw new IllegalStateException("Remote index id "
+ remoteIndexId + " did not match input index id "
+ indexId);
}
int remoteFileId = reader.readUnsignedShort();
if (fileId != remoteFileId) {
throw new IllegalStateException("Remote file id "
+ remoteFileId + " did not match input file id "
+ fileId);
}
FileResult result = downloadCompressedFile(indexId, fileId);
if (shouldDecompress) {
result.decompress(null);
}
return result;
}
示例4: toArray
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public int[] toArray ()
{
final ByteBuf buf = Unpooled.buffer ( 4 );
buf.writeMedium ( this.address );
return new int[] { buf.getUnsignedByte ( 0 ), buf.getUnsignedByte ( 1 ), buf.getUnsignedByte ( 2 ) };
}