本文整理汇总了Java中io.netty.buffer.ByteBuf.writeByte方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.writeByte方法的具体用法?Java ByteBuf.writeByte怎么用?Java ByteBuf.writeByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.writeByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, ConnectionResponse msg, ByteBuf out) throws Exception {
ChannelPipeline pipeline = ctx.pipeline();
switch (msg.getType()) {
case HANDSHAKE_CONNECTION:
pipeline.addAfter("decoder", "handshake.encoder", new HandshakeEncoder());
pipeline.replace("decoder", "handshake.decoder", new HandshakeDecoder());
break;
case LOGIN_CONNECTION:
out.writeByte(ClientMessage.SUCCESSFUL_CONNECTION.getId());
pipeline.addAfter("decoder", "login.encoder", new LoginEncoder());
pipeline.replace("decoder", "login.decoder", new LoginDecoder());
break;
}
pipeline.remove(this);
}
示例2: decodeConnectionConfirm
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Test
@Tag("fast")
public void decodeConnectionConfirm() throws Exception {
ChannelHandlerContext ctx = new MockChannelHandlerContext();
ByteBuf buf = Unpooled.buffer();
ArrayList<Object> out = new ArrayList<>();
buf.writeByte(0x6); // header length
buf.writeByte(TpduCode.CONNECTION_CONFIRM.getCode());
buf.writeShort(0x01); // destination reference
buf.writeShort(0x02); // source reference
buf.writeByte(ProtocolClass.CLASS_0.getCode());
IsoOnTcpMessage in = new IsoOnTcpMessage(buf);
isoTPProtocol.decode(ctx, in, out);
assertTrue(out.size() == 1, "Message not decoded");
ConnectionConfirmTpdu requestTpdu = (ConnectionConfirmTpdu) ((IsoTPMessage)out.get(0)).getTpdu();
assertTrue(requestTpdu.getTpduCode() == TpduCode.CONNECTION_CONFIRM, "Message code not correct");
assertTrue(requestTpdu.getDestinationReference() == (short) 0x1, "Message destination reference not correct");
assertTrue(requestTpdu.getSourceReference() == (short) 0x2, "Message source reference not correct");
assertTrue(requestTpdu.getProtocolClass() == ProtocolClass.CLASS_0, "Message protocol class reference not correct");
assertTrue(requestTpdu.getParameters().isEmpty(), "Message contains paramaters");
}
示例3: decodeConnectionRequest
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Test
@Tag("fast")
public void decodeConnectionRequest() throws Exception {
ChannelHandlerContext ctx = new MockChannelHandlerContext();
ByteBuf buf = Unpooled.buffer();
ArrayList<Object> out = new ArrayList<>();
buf.writeByte(0x6); // header length
buf.writeByte(TpduCode.CONNECTION_REQUEST.getCode());
buf.writeShort(0x01); // destination reference
buf.writeShort(0x02); // source reference
buf.writeByte(ProtocolClass.CLASS_0.getCode());
IsoOnTcpMessage in = new IsoOnTcpMessage(buf);
isoTPProtocol.decode(ctx, in, out);
assertTrue(out.size() == 1, "Message not decoded");
ConnectionRequestTpdu requestTpdu = (ConnectionRequestTpdu) ((IsoTPMessage)out.get(0)).getTpdu();
assertTrue(requestTpdu.getTpduCode() == TpduCode.CONNECTION_REQUEST, "Message code not correct");
assertTrue(requestTpdu.getDestinationReference() == (short) 0x1, "Message destination reference not correct");
assertTrue(requestTpdu.getSourceReference() == (short) 0x2, "Message source reference not correct");
assertTrue(requestTpdu.getProtocolClass() == ProtocolClass.CLASS_0, "Message protocol class reference not correct");
assertTrue(requestTpdu.getParameters().isEmpty(), "Message contains paramaters");
}
示例4: decodeDataEOT
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Test
@Tag("fast")
public void decodeDataEOT() throws Exception {
ChannelHandlerContext ctx = new MockChannelHandlerContext();
ByteBuf buf = Unpooled.buffer();
ArrayList<Object> out = new ArrayList<>();
buf.writeByte(0x3); // header length
buf.writeByte(TpduCode.DATA.getCode());
buf.writeByte((byte) 0x81); // Tpdu code + EOT
IsoOnTcpMessage in = new IsoOnTcpMessage(buf);
isoTPProtocol.decode(ctx, in, out);
assertTrue(out.size() == 1, "Message not decoded");
DataTpdu requestTpdu = (DataTpdu) ((IsoTPMessage)out.get(0)).getTpdu();
assertTrue(requestTpdu.getTpduCode() == TpduCode.DATA, "Message code not correct");
assertTrue(requestTpdu.getTpduRef() == (short) 0x1, "Message Tpdu reference not correct");
assertTrue(requestTpdu.isEot(), "Message EOT not correct");
assertTrue(requestTpdu.getParameters().isEmpty(), "Message contains paramaters");
}
示例5: connectionRequestTpdu
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Test
@Tag("Fast")
void connectionRequestTpdu() {
short destinationReference = 0x1;
short sourceReference = 0x2;
ProtocolClass protocolClass = ProtocolClass.CLASS_0;
List<Parameter> parameters = Collections.emptyList();
ByteBuf userData = Unpooled.buffer();
userData.writeByte(0x33);
ConnectionRequestTpdu tpdu = new ConnectionRequestTpdu(destinationReference, sourceReference, protocolClass, parameters, userData);
assertTrue(tpdu.getTpduCode() == TpduCode.CONNECTION_REQUEST);
assertTrue(tpdu.getDestinationReference() == 0x1, "Unexpected destination reference");
assertTrue(tpdu.getSourceReference() == 0x2, "Unexpected source reference");
assertTrue(tpdu.getProtocolClass() == ProtocolClass.CLASS_0);
assertTrue(tpdu.getParameters().isEmpty(), "Unexpected parameters");
assertTrue(tpdu.getUserData().readByte() == (byte) 0x33, "Unexpected user data");
}
示例6: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, Codable msg, ByteBuf out) throws Exception {
out.writeShort(CodecProtocol.MAGIC);
out.writeByte(msg.getType().ordinal());
byte[] bytes = serializer.serialize(msg);
int length = bytes.length;
out.writeInt(length).writeBytes(bytes);
}
示例7: encodeConnAckMessage
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static ByteBuf encodeConnAckMessage(
ByteBufAllocator byteBufAllocator,
MqttConnAckMessage message) {
ByteBuf buf = byteBufAllocator.buffer(4);
buf.writeByte(getFixedHeaderByte1(message.fixedHeader()));
buf.writeByte(2);
buf.writeByte(message.variableHeader().isSessionPresent() ? 0x01 : 0x00);
buf.writeByte(message.variableHeader().connectReturnCode().byteValue());
return buf;
}
示例8: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext channelHandlerContext, SkyllaPacket packet,
ByteBuf byteBuf) throws Exception {
byte packetId = this.protocol.getPacketId(packet);
// write packet id
byteBuf.writeByte(packetId);
// Encode Packet
packet.write(new SkyllaBuffer(byteBuf));
}
示例9: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void encode(ByteBuf buf) {
this.writeString(prefix, buf);
buf.writeByte(this.type.ordinal());
if (type == ServerType.SPIGOT)
buf.writeInt(this.bukkitPort);
}
示例10: writeItemStack
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static void writeItemStack( ItemStack itemStack, ByteBuf buf ) {
if( itemStack == null || itemStack.getType() == Material.AIR ) {
buf.writeShort( -1 );
} else {
buf.writeShort( itemStack.getTypeId() );
buf.writeByte( itemStack.getAmount() );
buf.writeShort( itemStack.getDurability() );
writeNbtTag( new NBTTagCompound( "ItemStack" ), buf ); // todo change
}
}
示例11: getStringBuffer
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private ByteBuf getStringBuffer(String string)
{
ByteBuf bytebuf = Unpooled.buffer();
bytebuf.writeByte(255);
char[] achar = string.toCharArray();
bytebuf.writeShort(achar.length);
for (char c0 : achar)
{
bytebuf.writeChar(c0);
}
return bytebuf;
}
示例12: toBytes
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
buf.writeByte(type.ordinal());
buf.writeInt(values.length);
for (int i = 0; i < types.length; i++) {
buf.writeByte(types[i]);
PacketUpdateGui.writeField(buf, values[i], types[i]);
}
ByteBufUtils.writeTag(buf, extraData);
}
示例13: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext channelHandlerContext, OutboundMsg msg, ByteBuf out) throws Exception {
byte type = msg.getType();
byte opt = msg.getOpt();
String msgStr = msg.getMsgStr();
byte[] data = msg.getData();
byte[] msgBytes = msgStr.getBytes(Charset.forName("utf-8"));
// 文本消息长度
int msgLength = msgBytes.length;
// 二进制数据长度
int dataLength = data == null ? 0 : data.length;
// 总消息长度
int allDataLength = msgLength + dataLength + OTHER_INFO_LENGTH;
out.writeBytes(OutboundMsg.getHEADER());//输出头部标识
out.writeInt(allDataLength);//其后所有的数据长度(字节)
out.writeByte(type);//数据类型
out.writeByte(opt);//操作类型
out.writeInt(msgLength);//信息数据长度(字节)
out.writeBytes(msgBytes);//信息字符串内容(已加密,字节)
if (data != null) {
out.writeBytes(data);//二进制数据
}
byte[] bytesToCheck = new byte[allDataLength - 1];
out.getBytes(7, bytesToCheck);
byte check = calculate(bytesToCheck);
out.writeByte(check);//冗余校验值
}
示例14: processDATA
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private void processDATA ( final ChannelHandlerContext ctx, final byte b )
{
final ByteBuf data = ctx.attr ( ATTR_DATA_BUFFER ).get ();
data.writeByte ( b );
if ( data.readableBytes () >= ctx.attr ( ATTR_EXPECTED_LENGTH ).get () )
{
ctx.attr ( ATTR_STATE ).set ( State.TRAILER );
}
}
示例15: encodeMessageWithOnlySingleByteFixedHeader
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private static ByteBuf encodeMessageWithOnlySingleByteFixedHeader(
ByteBufAllocator byteBufAllocator,
MqttMessage message) {
MqttFixedHeader mqttFixedHeader = message.fixedHeader();
ByteBuf buf = byteBufAllocator.buffer(2);
buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
buf.writeByte(0);
return buf;
}