Search in sources :

Example 86 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project neo4j by neo4j.

the class ReplicatedTokenRequestSerializer method extractCommands.

static Collection<StorageCommand> extractCommands(byte[] commandBytes) {
    ByteBuf txBuffer = Unpooled.wrappedBuffer(commandBytes);
    NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(txBuffer);
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    LogEntryCommand entryRead;
    List<StorageCommand> commands = new LinkedList<>();
    try {
        while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
            commands.add(entryRead.getXaCommand());
        }
    } catch (IOException e) {
        // TODO: Handle or throw.
        e.printStackTrace();
    }
    return commands;
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) LinkedList(java.util.LinkedList) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 87 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project netty by netty.

the class DatagramDnsQueryDecoder method decode.

@Override
protected void decode(ChannelHandlerContext ctx, DatagramPacket packet, List<Object> out) throws Exception {
    final ByteBuf buf = packet.content();
    final DnsQuery query = newQuery(packet, buf);
    boolean success = false;
    try {
        final int questionCount = buf.readUnsignedShort();
        final int answerCount = buf.readUnsignedShort();
        final int authorityRecordCount = buf.readUnsignedShort();
        final int additionalRecordCount = buf.readUnsignedShort();
        decodeQuestions(query, buf, questionCount);
        decodeRecords(query, DnsSection.ANSWER, buf, answerCount);
        decodeRecords(query, DnsSection.AUTHORITY, buf, authorityRecordCount);
        decodeRecords(query, DnsSection.ADDITIONAL, buf, additionalRecordCount);
        out.add(query);
        success = true;
    } finally {
        if (!success) {
            query.release();
        }
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf)

Example 88 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project netty by netty.

the class HttpContentDecoder method cleanup.

private void cleanup() {
    if (decoder != null) {
        // Clean-up the previous decoder if not cleaned up correctly.
        if (decoder.finish()) {
            for (; ; ) {
                ByteBuf buf = decoder.readInbound();
                if (buf == null) {
                    break;
                }
                // Release the buffer
                buf.release();
            }
        }
        decoder = null;
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf)

Example 89 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project netty by netty.

the class RedisEncoder method writeString.

private static void writeString(ByteBufAllocator allocator, byte type, String content, List<Object> out) {
    ByteBuf buf = allocator.ioBuffer(RedisConstants.TYPE_LENGTH + ByteBufUtil.utf8MaxBytes(content) + RedisConstants.EOL_LENGTH);
    buf.writeByte(type);
    ByteBufUtil.writeUtf8(buf, content);
    buf.writeShort(RedisConstants.EOL_SHORT);
    out.add(buf);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf)

Example 90 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project netty by netty.

the class MqttEncoder method encodePublishMessage.

private static ByteBuf encodePublishMessage(ByteBufAllocator byteBufAllocator, MqttPublishMessage message) {
    MqttFixedHeader mqttFixedHeader = message.fixedHeader();
    MqttPublishVariableHeader variableHeader = message.variableHeader();
    ByteBuf payload = message.payload().duplicate();
    String topicName = variableHeader.topicName();
    byte[] topicNameBytes = encodeStringUtf8(topicName);
    int variableHeaderBufferSize = 2 + topicNameBytes.length + (mqttFixedHeader.qosLevel().value() > 0 ? 2 : 0);
    int payloadBufferSize = payload.readableBytes();
    int variablePartSize = variableHeaderBufferSize + payloadBufferSize;
    int fixedHeaderBufferSize = 1 + getVariableLengthInt(variablePartSize);
    ByteBuf buf = byteBufAllocator.buffer(fixedHeaderBufferSize + variablePartSize);
    buf.writeByte(getFixedHeaderByte1(mqttFixedHeader));
    writeVariableLengthInt(buf, variablePartSize);
    buf.writeShort(topicNameBytes.length);
    buf.writeBytes(topicNameBytes);
    if (mqttFixedHeader.qosLevel().value() > 0) {
        buf.writeShort(variableHeader.messageId());
    }
    buf.writeBytes(payload);
    return buf;
}
Also used : ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)5080 Test (org.junit.Test)1813 Test (org.junit.jupiter.api.Test)680 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)377 ArrayList (java.util.ArrayList)301 IOException (java.io.IOException)297 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)200 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)182 ByteBuffer (java.nio.ByteBuffer)167 InetSocketAddress (java.net.InetSocketAddress)145 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)144 Test (org.testng.annotations.Test)140 Channel (io.netty.channel.Channel)137 List (java.util.List)134 ChannelFuture (io.netty.channel.ChannelFuture)128 Map (java.util.Map)118 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)107 Position (org.traccar.model.Position)105 DeviceSession (org.traccar.DeviceSession)100 NetworkMessage (org.traccar.NetworkMessage)93