当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuf.writeByte方法代码示例

本文整理汇总了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);
}
 
开发者ID:jordanabrahambaws,项目名称:Quavo,代码行数:19,代码来源:ConnectionEncoder.java

示例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");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:27,代码来源:IsoTPProtocolTest.java

示例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");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:27,代码来源:IsoTPProtocolTest.java

示例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");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:24,代码来源:IsoTPProtocolTest.java

示例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");
}
 
开发者ID:apache,项目名称:incubator-plc4x,代码行数:21,代码来源:IsotpModelTests.java

示例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);
}
 
开发者ID:DanceFirstThinkLater,项目名称:PetiteRPC,代码行数:9,代码来源:Encoder.java

示例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;
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:12,代码来源:MqttEncoder.java

示例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));
}
 
开发者ID:D3adspaceEnterprises,项目名称:skylla,代码行数:13,代码来源:SkyllaPacketEncoder.java

示例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);
}
 
开发者ID:CentauriCloud,项目名称:CentauriCloud,代码行数:8,代码来源:PacketServerRegister.java

示例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
    }
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:11,代码来源:Message.java

示例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;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:15,代码来源:PingResponseHandler.java

示例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);
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:12,代码来源:PacketDescription.java

示例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);//冗余校验值
}
 
开发者ID:wyp0596,项目名称:elegant-springboot,代码行数:34,代码来源:MsgEncoder.java

示例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 );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:10,代码来源:FrameCodec.java

示例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;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:11,代码来源:MqttEncoder.java


注:本文中的io.netty.buffer.ByteBuf.writeByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。