List of usage examples for io.netty.buffer ByteBuf writeLong
public abstract ByteBuf writeLong(long value);
From source file:org.spout.vanilla.protocol.codec.player.PlayerTimeCodec.java
License:Open Source License
@Override public ByteBuf encode(PlayerTimeMessage message) throws IOException { ByteBuf buffer = Unpooled.buffer(16); buffer.writeLong(message.getAge()); buffer.writeLong(message.getTime()); return buffer; }
From source file:org.starmod.net.object.field.type.NetworkLong.java
License:MIT License
@Override public void encode(ByteBuf buf) { buf.writeLong(getValue()); }
From source file:org.starnub.starbounddata.packets.Packet.java
License:Open Source License
/** * Recommended: For Plugin Developers & Anyone else. * <p>//from w w w. j a va2s . c om * Uses: This will write a uuid value to a {@link io.netty.buffer.ByteBuf} and advanced the buffer writer index by 16 bytes * <p> * * @param out ByteBuf representing the buffer to be written to * @param uuid uuid value to be written to the buffer */ public static void writeUUID(ByteBuf out, UUID uuid) { out.writeLong(uuid.getMostSignificantBits()); out.writeLong(uuid.getLeastSignificantBits()); }
From source file:org.stem.utils.BBUtils.java
License:Apache License
public static void writeUuid(UUID value, ByteBuf dest) { dest.writeLong(value.getMostSignificantBits()).writeLong(value.getLeastSignificantBits()); }
From source file:org.tiger.netty.rpc.all.codec.NettyMessageEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, NettyMessage msg, ByteBuf sendBuf) throws Exception { System.out.println("NettyMessageEncoder encode ..." + System.currentTimeMillis()); if (msg == null || msg.getHeader() == null) throw new Exception("The encode message is null"); sendBuf.writeInt((msg.getHeader().getCrcCode())); //print(sendBuf); sendBuf.writeInt((msg.getHeader().getLength())); //print(sendBuf); sendBuf.writeLong((msg.getHeader().getSessionID())); //print(sendBuf); sendBuf.writeByte((msg.getHeader().getType())); //print(sendBuf); sendBuf.writeByte((msg.getHeader().getPriority())); //print(sendBuf); sendBuf.writeInt((msg.getHeader().getAttachment().size())); //print(sendBuf); String key = null;//from w w w. java2 s . c o m byte[] keyArray = null; Object value = null; for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) { key = param.getKey(); keyArray = key.getBytes("UTF-8"); sendBuf.writeInt(keyArray.length); sendBuf.writeBytes(keyArray); value = param.getValue(); marshallingEncoder.encode(value, sendBuf); } key = null; keyArray = null; value = null; if (msg.getBody() != null) { marshallingEncoder.encode(msg.getBody(), sendBuf); } else { sendBuf.writeInt(0); //print(sendBuf); } System.out.println(sendBuf.readableBytes()); //???4 int? 8?4?int??4intlengthlengthlength????8 sendBuf.setInt(4, sendBuf.readableBytes() - 8); //print(sendBuf); //sendBuf.writeInt(0); }
From source file:org.traccar.protocol.AtrackProtocolDecoder.java
License:Apache License
private static void sendResponse(Channel channel, SocketAddress remoteAddress, long rawId, int index) { if (channel != null) { ByteBuf response = Unpooled.buffer(12); response.writeShort(0xfe02);/*from ww w . j a va2 s . c o m*/ response.writeLong(rawId); response.writeShort(index); channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } }
From source file:org.wso2.carbon.tcp.transport.util.BinaryEventConverter.java
License:Open Source License
public static void convertToBinaryMessage(List<SiddhiEventComposite> events, String sessionId, ByteBuf messageBuffer) throws IOException { int messageSize = 8 + sessionId.length(); List<ByteBuf> eventBuffers = new ArrayList<ByteBuf>(); for (SiddhiEventComposite event : events) { int eventSize = getEventSize(event); messageSize += eventSize + 4;/*from w w w. ja v a2s. c om*/ Event siddhiEvent = event.getSiddhiEvent(); ByteBuf eventDataBuffer = buffer(4 + eventSize); //ByteBuffer eventDataBuffer = ByteBuffer.allocate(4 + eventSize); eventDataBuffer.writeInt(eventSize); eventDataBuffer.writeLong(siddhiEvent.getTimestamp()); eventDataBuffer.writeInt(event.getStreamID().length()); eventDataBuffer.writeBytes(event.getStreamID().getBytes(BinaryMessageConstants.DEFAULT_CHARSET)); if (siddhiEvent.getData() != null && siddhiEvent.getData().length != 0) { for (Object aData : siddhiEvent.getData()) { BinaryMessageConverterUtil.assignData(aData, eventDataBuffer); } } /* if (event.getArbitraryDataMap() != null && event.getArbitraryDataMap().size() != 0) { for (Map.Entry<String, String> aArbitraryData : event.getArbitraryDataMap().entrySet()) { assignData(aArbitraryData.getKey(), eventDataBuffer); assignData(aArbitraryData.getValue(), eventDataBuffer); } }*/ eventBuffers.add(eventDataBuffer); } messageBuffer.writeByte((byte) 2); //1 messageBuffer.writeInt(messageSize); //4 messageBuffer.writeInt(sessionId.length()); //4 messageBuffer.writeBytes(sessionId.getBytes(BinaryMessageConstants.DEFAULT_CHARSET)); messageBuffer.writeInt(events.size()); //4 for (ByteBuf byteBuf : eventBuffers) { messageBuffer.writeBytes(byteBuf); } }
From source file:org.wso2.carbon.tcp.transport.util.BinaryMessageConverterUtil.java
License:Open Source License
public static void assignData(Object data, ByteBuf eventDataBuffer) throws IOException { if (data instanceof String) { eventDataBuffer.writeInt(((String) data).length()); eventDataBuffer.writeBytes((((String) data).getBytes(BinaryMessageConstants.DEFAULT_CHARSET))); } else if (data instanceof Integer) { eventDataBuffer.writeInt((Integer) data); } else if (data instanceof Long) { eventDataBuffer.writeLong((Long) data); } else if (data instanceof Float) { eventDataBuffer.writeFloat((Float) data); } else if (data instanceof Double) { eventDataBuffer.writeDouble((Double) data); } else if (data instanceof Boolean) { eventDataBuffer.writeByte((byte) (((Boolean) data) ? 1 : 0)); } else {/*from w ww . j ava 2 s . c o m*/ eventDataBuffer.writeInt(0); } }
From source file:org.wso2.siddhi.tcp.transport.converter.BinaryEventConverter.java
License:Open Source License
public static void convertToBinaryMessage(EventComposite eventComposite, ByteBuf messageBuffer) throws IOException { String sessionId = eventComposite.getSessionId(); String streamId = eventComposite.getStreamId(); int eventCount = eventComposite.getEvents().length; int messageSize = 4 + sessionId.length() + 4 + streamId.length() + 4; List<ByteBuf> eventBuffers = new ArrayList<ByteBuf>(); for (Event event : eventComposite.getEvents()) { int eventSize = getEventSize(event); messageSize += eventSize + 4;//from w ww. j a v a2 s . com ByteBuf eventDataBuffer = buffer(4 + eventSize); //ByteBuffer eventDataBuffer = ByteBuffer.allocate(4 + eventSize); eventDataBuffer.writeInt(eventSize); eventDataBuffer.writeLong(event.getTimestamp()); if (event.getData() != null && event.getData().length != 0) { for (Object aData : event.getData()) { BinaryMessageConverterUtil.assignData(aData, eventDataBuffer); } } eventBuffers.add(eventDataBuffer); } /* if (event.getArbitraryDataMap() != null && event.getArbitraryDataMap().size() != 0) { for (Map.Entry<String, String> aArbitraryData : event.getArbitraryDataMap().entrySet()) { assignData(aArbitraryData.getKey(), eventDataBuffer); assignData(aArbitraryData.getValue(), eventDataBuffer); } } */ messageBuffer.writeByte((byte) 2); //1 messageBuffer.writeInt(messageSize); //4 messageBuffer.writeInt(sessionId.length()); //4 messageBuffer.writeBytes(sessionId.getBytes(Constant.DEFAULT_CHARSET)); messageBuffer.writeInt(streamId.length()); //4 messageBuffer.writeBytes(streamId.getBytes(Constant.DEFAULT_CHARSET)); messageBuffer.writeInt(eventCount); //4 for (ByteBuf byteBuf : eventBuffers) { messageBuffer.writeBytes(byteBuf); } }
From source file:org.wso2.siddhi.tcp.transport.utils.BinaryMessageConverterUtil.java
License:Open Source License
public static void assignData(Object data, ByteBuf eventDataBuffer) throws IOException { if (data instanceof String) { eventDataBuffer.writeInt(((String) data).length()); eventDataBuffer.writeBytes((((String) data).getBytes(Constant.DEFAULT_CHARSET))); } else if (data instanceof Integer) { eventDataBuffer.writeInt((Integer) data); } else if (data instanceof Long) { eventDataBuffer.writeLong((Long) data); } else if (data instanceof Float) { eventDataBuffer.writeFloat((Float) data); } else if (data instanceof Double) { eventDataBuffer.writeDouble((Double) data); } else if (data instanceof Boolean) { eventDataBuffer.writeByte((byte) (((Boolean) data) ? 1 : 0)); } else {/*from www . j av a 2 s.c o m*/ eventDataBuffer.writeInt(0); } }