當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。