當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuf.writeShort方法代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBuf.writeShort方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.writeShort方法的具體用法?Java ByteBuf.writeShort怎麽用?Java ByteBuf.writeShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.writeShort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: write

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    SendableMsgContainer message = (SendableMsgContainer) msg;
    ByteBuf byteBuf = ctx.alloc().buffer();
    FrameMajorHeader header = message.getFrameHeader();
    byteBuf.writeByte(FrameSetting.MAJOR_FRAME_HEAD_1);
    byteBuf.writeByte(FrameSetting.MAJOR_FRAME_HEAD_2);
    byteBuf.writeByte(header.getGroupId());
    byteBuf.writeByte(header.getMsgId());
    byteBuf.writeByte(header.getDeviceId());
    byteBuf.writeByte(header.getBackupMsg());
    byteBuf.writeShort(header.getDataLength());

    List<ByteBuf> dataList = message.getDataList();
    dataList.forEach(byteBuf::writeBytes);
    ctx.writeAndFlush(byteBuf);
}
 
開發者ID:bitkylin,項目名稱:ClusterDeviceControlPlatform,代碼行數:18,代碼來源:MsgRecognitionOutBoundHandler.java

示例2: decodeDisconnectionRequest

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Test
@Tag("fast")
public void decodeDisconnectionRequest() throws Exception {
    ChannelHandlerContext ctx = new MockChannelHandlerContext();
    ByteBuf buf = Unpooled.buffer();
    ArrayList<Object> out = new ArrayList<>();

    buf.writeByte(0x6); // header length
    buf.writeByte(TpduCode.DISCONNECT_REQUEST.getCode());
    buf.writeShort(0x01); // destination reference
    buf.writeShort(0x02); // source reference
    buf.writeByte(DisconnectReason.NORMAL.getCode());
    IsoOnTcpMessage in = new IsoOnTcpMessage(buf);

    isoTPProtocol.decode(ctx, in, out);

    assertTrue(out.size() == 1, "Message not decoded");

    DisconnectRequestTpdu requestTpdu = (DisconnectRequestTpdu) ((IsoTPMessage)out.get(0)).getTpdu();

    assertTrue(requestTpdu.getTpduCode() == TpduCode.DISCONNECT_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.getDisconnectReason() == DisconnectReason.NORMAL, "Message disconnect reason not correct");
    assertTrue(requestTpdu.getParameters().isEmpty(), "Message contains paramaters");
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:27,代碼來源:IsoTPProtocolTest.java

示例3: sendTo

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public void sendTo(IMessage message, EntityPlayerMP player)
{
    if(useUdp && discriminators.containsKey(message.getClass())) {
    	InetSocketAddress address=TF2weapons.udpServer.outboundTargets.get(player.getCapability(TF2weapons.PLAYER_CAP, null).udpServerId);
    	if (address != null) {
 		ByteBuf buffer = Unpooled.buffer();
 		buffer.writeShort(0);
 		buffer.writeByte(discriminators.get(message.getClass()));
 		message.toBytes(buffer);
 		DatagramPacket packet = new DatagramPacket(buffer, address);
 		TF2weapons.udpServer.channel.writeAndFlush(packet);
    	}
    }
    else {
    	super.sendTo(message, player);
    }
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:18,代碼來源:TF2NetworkWrapper.java

示例4: serialize

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void serialize(ByteBuf buf) {
  super.serialize(buf);
  int w = getPartKey().getStartRow();
  for (int i = 0; i < updates.length; i ++) {
    if (updates[i] != null) {
      buf.writeInt(w + i);
      Short2IntOpenHashMap map = updates[i];
      buf.writeShort(map.size());
      ObjectIterator<Short2IntMap.Entry> iter = map.short2IntEntrySet().fastIterator();
      while (iter.hasNext()) {
        Short2IntMap.Entry entry = iter.next();
        buf.writeShort(entry.getShortKey());
        buf.writeInt(entry.getIntValue());
      }
    }
  }

}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:20,代碼來源:CSRPartUpdateParam.java

示例5: toBytes

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void toBytes(ByteBuf buf) {
	ByteArrayOutputStream obj = new ByteArrayOutputStream();

	try {
		GZIPOutputStream gzip = new GZIPOutputStream(obj);
		ObjectOutputStream objStream = new ObjectOutputStream(gzip);
		objStream.writeObject(values);
		objStream.close();
	}
	catch (IOException e) {
		Throwables.propagate(e);
	}
	buf.writeShort(obj.size());
	buf.writeBytes(obj.toByteArray());
}
 
開發者ID:p455w0rd,項目名稱:DankNull,代碼行數:17,代碼來源:PacketConfigSync.java

示例6: writeObjectArray

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static void writeObjectArray(ByteBuf out, List<Object> objects) {
    for (Object o : objects) {
        if (o instanceof Byte) {
            out.writeByte((Byte) o);
        } else if (o instanceof Boolean) {
            out.writeBoolean((Boolean) o);
        } else if (o instanceof Integer) {
            out.writeInt((Integer) o);
        } else if (o instanceof Float) {
            out.writeFloat((Float) o);
        } else if (o instanceof Double) {
            out.writeDouble((Double) o);
        } else if (o instanceof Short) {
            out.writeShort((Short) o);
        } else if (o instanceof Long) {
            out.writeLong((Long) o);
        }
    }
}
 
開發者ID:AlexMog,項目名稱:SurvivalMMO,代碼行數:20,代碼來源:Packet.java

示例7: sendToServer

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public void sendToServer(IMessage message)
{
    if(useUdp && TF2UdpClient.instance != null && discriminators.containsKey(message.getClass())) {
    	InetSocketAddress address=TF2UdpClient.instance.address;
    	//System.out.println("Addr: "+address);
    	if (address != null) {
 		ByteBuf buffer = Unpooled.buffer();
 		buffer.writeShort(TF2UdpClient.playerId);
 		buffer.writeShort(0);
 		buffer.writeByte(discriminators.get(message.getClass()));
 		message.toBytes(buffer);
 		DatagramPacket packet = new DatagramPacket(buffer, address);
 		TF2UdpClient.instance.channel.writeAndFlush(packet);
    	}
    }
    else {
    	super.sendToServer(message);
    }
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:20,代碼來源:TF2NetworkWrapper.java

示例8: writeString

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static void writeString(String str, ByteBuf cb)
{
    int writerIndex = cb.writerIndex();
    cb.writeShort(0);
    int lengthBytes = ByteBufUtil.writeUtf8(cb, str);
    cb.setShort(writerIndex, lengthBytes);
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:8,代碼來源:CBUtil.java

示例9: writeVarShort

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static void writeVarShort(ByteBuf buf, int toWrite)
{
    int low = toWrite & 0x7FFF;
    int high = ( toWrite & 0x7F8000 ) >> 15;
    if (high != 0)
    {
        low = low | 0x8000;
    }
    buf.writeShort(low);
    if (high != 0)
    {
        buf.writeByte(high);
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:15,代碼來源:ByteBufUtils.java

示例10: decodeCalledParameter

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Test
@Tag("fast")
public void decodeCalledParameter() throws Exception {
    ChannelHandlerContext ctx = new MockChannelHandlerContext();
    ByteBuf buf = Unpooled.buffer();
    ArrayList<Object> out = new ArrayList<>();

    buf.writeByte(0x8); // header length
    buf.writeByte(TpduCode.TPDU_ERROR.getCode());
    buf.writeShort(0x01); // destination reference
    buf.writeByte(RejectCause.REASON_NOT_SPECIFIED.getCode()); // reject clause
    buf.writeByte(ParameterCode.CALLED_TSAP.getCode());
    buf.writeByte(0x2); // parameter length
    buf.writeByte(DeviceGroup.PG_OR_PC.getCode());
    buf.writeByte((byte) ((0x2 << 4) | 0x3));
    IsoOnTcpMessage in = new IsoOnTcpMessage(buf);

    isoTPProtocol.decode(ctx, in, out);

    assertTrue(out.size() == 1, "Message not decoded");

    ErrorTpdu errorTpdu = (ErrorTpdu) ((IsoTPMessage)out.get(0)).getTpdu();

    assertTrue(errorTpdu.getTpduCode() == TpduCode.TPDU_ERROR, "Message code not correct");
    assertTrue(errorTpdu.getDestinationReference() == (short) 0x1, "Message destination reference not correct");
    assertTrue(errorTpdu.getRejectCause() == RejectCause.REASON_NOT_SPECIFIED, "Message reject cause not correct");
    assertTrue(errorTpdu.getParameters().size() == 1, "Incorrect number of parameters");
    CalledTsapParameter parameter = (CalledTsapParameter) errorTpdu.getParameters().get(0);
    assertTrue(parameter.getType() == ParameterCode.CALLED_TSAP, "Parameter type incorrect");
    assertTrue(parameter.getDeviceGroup() == DeviceGroup.PG_OR_PC, "Device group incorrect");
    assertTrue(parameter.getRackNumber() == 0x2, "Rack number incorrect");
    assertTrue(parameter.getSlotNumber() == 0x3, "Slot number incorrect");
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:34,代碼來源:IsoTPProtocolTest.java

示例11: encode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, GamePacketResponse msg, ByteBuf out) throws Exception {
	PacketEncoder<PacketContext> packet = msg.getPacket();
	PacketType type = packet.getPacket().getType();
	ByteBuf buffer = packet.getBuilder().getBuffer();

	out.writeByte(packet.getPacket().getId()/* + encoder.nextInt() */);
	if (type == PacketType.VARIABLE_BYTE) {
		out.writeByte(buffer.writerIndex());
	} else if (type == PacketType.VARIABLE_SHORT) {
		out.writeShort(buffer.writerIndex());
	}
	out.writeBytes(buffer);
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:15,代碼來源:GamePacketEncoder.java

示例12: write

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void write( ByteBuf buf ) throws IOException {
    writeVarInt( entityId, buf );
    buf.writeShort( deltaX );
    buf.writeShort( deltaY );
    buf.writeShort( deltaZ );
    buf.writeByte( toAngle( yaw ) );
    buf.writeByte( toAngle( pitch ) );
    buf.writeBoolean( onGround );
}
 
開發者ID:lukas81298,項目名稱:FlexMC,代碼行數:11,代碼來源:MessageS27EntityRelMoveLook.java

示例13: writeMethod

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void writeMethod(ByteBuf buf) {
    buf.writeShort(0);
    queue.write(buf);
    exchange.write(buf);
    routingKey.write(buf);
    buf.writeBoolean(noWait);
    arguments.write(buf);
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:10,代碼來源:QueueBind.java

示例14: beforeWriteBody

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void beforeWriteBody(ByteBuf buf, short messageId) {
	// 消息長度(包括消息Id)
	buf.writeShort(0);
	// 消息Id
	buf.writeShort(messageId);
}
 
開發者ID:HankXV,項目名稱:Limitart,代碼行數:8,代碼來源:AbstractBinaryEncoder.java

示例15: 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


注:本文中的io.netty.buffer.ByteBuf.writeShort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。