当前位置: 首页>>代码示例>>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;未经允许,请勿转载。