List of usage examples for io.netty.buffer ByteBuf writeLong
public abstract ByteBuf writeLong(long value);
From source file:io.grpc.netty.NettyHandlerTestBase.java
License:Apache License
@Test public void dataSizeSincePingAccumulates() throws Exception { manualSetUp();/*from w ww. j ava 2 s .com*/ makeStream(); AbstractNettyHandler handler = (AbstractNettyHandler) handler(); handler.setAutoTuneFlowControl(true); long frameData = 123456; ByteBuf buff = ctx().alloc().buffer(16); buff.writeLong(frameData); int length = buff.readableBytes(); channelRead(dataFrame(3, false, buff.copy())); channelRead(dataFrame(3, false, buff.copy())); channelRead(dataFrame(3, false, buff.copy())); assertEquals(length * 3, handler.flowControlPing().getDataSincePing()); }
From source file:io.grpc.netty.NettyHandlerTestBase.java
License:Apache License
@Test public void windowUpdateMatchesTarget() throws Exception { manualSetUp();//from w w w .j a v a 2 s. c o m Http2Stream connectionStream = connection().connectionStream(); Http2LocalFlowController localFlowController = connection().local().flowController(); makeStream(); AbstractNettyHandler handler = (AbstractNettyHandler) handler(); handler.setAutoTuneFlowControl(true); ByteBuf data = ctx().alloc().buffer(1024); while (data.isWritable()) { data.writeLong(1111); } int length = data.readableBytes(); ByteBuf frame = dataFrame(3, false, data.copy()); channelRead(frame); int accumulator = length; // 40 is arbitrary, any number large enough to trigger a window update would work for (int i = 0; i < 40; i++) { channelRead(dataFrame(3, false, data.copy())); accumulator += length; } long pingData = handler.flowControlPing().payload(); channelRead(pingFrame(true, pingData)); assertEquals(accumulator, handler.flowControlPing().getDataSincePing()); assertEquals(2 * accumulator, localFlowController.initialWindowSize(connectionStream)); }
From source file:io.hekate.network.netty.NettyMessageTest.java
License:Apache License
@Test public void testPreview() throws Exception { ByteBuf buf = Unpooled.buffer(); buf.writeByte(10);/*from w ww.j a v a 2 s . c o m*/ buf.writeBoolean(true); buf.writeInt(100); buf.writeLong(1000); buf.writeDouble(1.01); NettyMessage msg = new NettyMessage(buf, new Codec<Object>() { @Override public boolean isStateful() { return false; } @Override public Class<Object> baseType() { return Object.class; } @Override public Object decode(DataReader in) throws IOException { throw new AssertionError("Should not be called."); } @Override public void encode(Object obj, DataWriter out) throws IOException { throw new AssertionError("Should not be called."); } }); assertEquals((byte) 10, (byte) msg.preview(DataInput::readByte)); assertEquals(0, buf.readerIndex()); assertTrue(msg.previewBoolean(m -> { m.skipBytes(1); return m.readBoolean(); })); assertEquals(0, buf.readerIndex()); assertEquals(100, msg.previewInt(m -> { m.skipBytes(2); return m.readInt(); })); assertEquals(0, buf.readerIndex()); assertEquals(1000, msg.previewLong(m -> { m.skipBytes(6); return m.readLong(); })); assertEquals(0, buf.readerIndex()); assertEquals(1.01, msg.previewDouble(m -> { m.skipBytes(14); return m.readDouble(); }), 1000); assertEquals(0, buf.readerIndex()); assertEquals(1, buf.refCnt()); msg.release(); assertEquals(0, buf.refCnt()); }
From source file:io.hydramq.core.type.converters.CursorInfoConverter.java
License:Open Source License
@Override public void write(ConversionContext context, CursorInfo info, ByteBuf buffer) { buffer.writeLong(info.getOffset()).writeLong(info.getHead()).writeLong(info.getTail()); }
From source file:io.hydramq.core.type.converters.MessagePropertiesConverter.java
License:Open Source License
@Override public void write(final ConversionContext context, final MessageProperties properties, final ByteBuf buffer) { int flags = 0; if (properties.getStringKeys().size() > 0) { flags = flags | HAS_STRING_PROPERTIES; }//from www. j av a 2s . c o m if (properties.getBooleanKeys().size() > 0) { flags = flags | HAS_BOOLEAN_PROPERTIES; } if (properties.getIntegerKeys().size() > 0) { flags = flags | HAS_INTEGER_PROPERTIES; } if (properties.getLongKeys().size() > 0) { flags = flags | HAS_LONG_PROPERTIES; } if (properties.getFloatKeys().size() > 0) { flags = flags | HAS_FLOAT_PROPERTIES; } if (properties.getDoubleKeys().size() > 0) { flags = flags | HAS_DOUBLE_PROPERTIES; } if (properties.getBytesKeys().size() > 0) { flags = flags | HAS_BYTES_PROPERTIES; } if (properties.getShortKeys().size() > 0) { flags = flags | HAS_SHORT_PROPERTIES; } if (properties.getByteKeys().size() > 0) { flags = flags | HAS_BYTE_PROPERTIES; } buffer.writeInt(flags); if (properties.getStringKeys().size() > 0) { buffer.writeInt(properties.getStringKeys().size()); for (String key : properties.getStringKeys()) { context.write(String.class, key, buffer); context.write(String.class, properties.getString(key), buffer); } } if (properties.getBooleanKeys().size() > 0) { buffer.writeInt(properties.getBooleanKeys().size()); for (String key : properties.getBooleanKeys()) { context.write(String.class, key, buffer); buffer.writeBoolean(properties.getBoolean(key)); } } if (properties.getIntegerKeys().size() > 0) { buffer.writeInt(properties.getIntegerKeys().size()); for (String key : properties.getIntegerKeys()) { context.write(String.class, key, buffer); buffer.writeInt(properties.getInteger(key)); } } if (properties.getLongKeys().size() > 0) { buffer.writeInt(properties.getLongKeys().size()); for (String key : properties.getLongKeys()) { context.write(String.class, key, buffer); buffer.writeLong(properties.getLong(key)); } } if (properties.getFloatKeys().size() > 0) { buffer.writeInt(properties.getFloatKeys().size()); for (String key : properties.getFloatKeys()) { context.write(String.class, key, buffer); buffer.writeFloat(properties.getFloat(key)); } } if (properties.getDoubleKeys().size() > 0) { buffer.writeInt(properties.getDoubleKeys().size()); for (String key : properties.getDoubleKeys()) { context.write(String.class, key, buffer); buffer.writeDouble(properties.getDouble(key)); } } if (properties.getBytesKeys().size() > 0) { buffer.writeInt(properties.getBytesKeys().size()); for (String key : properties.getBytesKeys()) { context.write(String.class, key, buffer); context.write(byte[].class, properties.getBytes(key), buffer); } } if (properties.getShortKeys().size() > 0) { buffer.writeInt(properties.getShortKeys().size()); for (String key : properties.getShortKeys()) { context.write(String.class, key, buffer); buffer.writeShort(properties.getShort(key)); } } if (properties.getByteKeys().size() > 0) { buffer.writeInt(properties.getByteKeys().size()); for (String key : properties.getByteKeys()) { context.write(String.class, key, buffer); buffer.writeByte(properties.getByte(key)); } } }
From source file:io.hydramq.core.type.converters.MessageSetConverter.java
License:Open Source License
@Override public void write(ConversionContext context, MessageSet messageSet, ByteBuf buffer) { buffer.writeLong(messageSet.startOffset()); buffer.writeInt(messageSet.size());/*from w w w. j a va 2s.com*/ messageSet.forEach(message -> context.write(Message.class, message, buffer)); }
From source file:io.hydramq.core.type.converters.PartitionIdConverter.java
License:Open Source License
@Override public void write(ConversionContext context, PartitionId instance, ByteBuf buffer) { buffer.writeLong(instance.getUUID().getMostSignificantBits()) .writeLong(instance.getUUID().getLeastSignificantBits()); }
From source file:io.hydramq.core.type.converters.PartitionInfoConverter.java
License:Open Source License
@Override public void write(final ConversionContext context, final PartitionInfo partitionInfo, final ByteBuf buffer) { buffer.writeLong(partitionInfo.head()); buffer.writeLong(partitionInfo.tail()); }
From source file:io.hydramq.core.type.converters.UUIDConverter.java
License:Open Source License
@Override public void write(ConversionContext context, UUID uuid, ByteBuf buffer) { buffer.writeLong(uuid.getMostSignificantBits()); buffer.writeLong(uuid.getLeastSignificantBits()); }
From source file:io.hydramq.core.type.converters.WriteCursorRequestConverter.java
License:Open Source License
@Override protected void writeObject(ConversionContext context, WriteCursorRequest request, ByteBuf buffer) { context.write(PartitionId.class, request.getPartitionId(), buffer); context.write(String.class, request.getCursorName(), buffer); buffer.writeLong(request.getOffset()); }