Example usage for io.netty.util Attribute set

List of usage examples for io.netty.util Attribute set

Introduction

In this page you can find the example usage for io.netty.util Attribute set.

Prototype

void set(T value);

Source Link

Document

Sets the value

Usage

From source file:org.lanternpowered.server.network.vanilla.message.codec.play.AbstractCodecPlayInOutCustomPayload.java

License:MIT License

private Message decode0(CodecContext context, ByteBuffer content, String channel) {
    if ("REGISTER".equals(channel)) {
        Set<String> channels = decodeChannels(content);
        Iterator<String> it = channels.iterator();
        while (it.hasNext()) {
            String channel0 = it.next();
            if (channel0.startsWith("FML")) {
                it.remove();//from  w  w  w .  j  a v a  2s.co m
            }
        }
        if (!channels.isEmpty()) {
            return new MessagePlayInOutRegisterChannels(channels);
        }
    } else if ("UNREGISTER".equals(channel)) {
        Set<String> channels = decodeChannels(content);
        Iterator<String> it = channels.iterator();
        while (it.hasNext()) {
            String channel0 = it.next();
            if (channel0.startsWith("FML")) {
                it.remove();
            }
        }
        if (!channels.isEmpty()) {
            return new MessagePlayInOutUnregisterChannels(channels);
        }
    } else if ("FML|MP".equals(channel)) {
        Attribute<MultiPartMessage> attribute = context.getChannel().attr(FML_MULTI_PART_MESSAGE);
        MultiPartMessage message0 = attribute.get();
        if (message0 == null) {
            String channel0 = content.readString();
            int parts = content.readByte() & 0xff;
            int size = content.readInteger();
            if (size <= 0 || size >= -16797616) {
                throw new CodecException(
                        "Received FML MultiPart packet outside of valid length bounds, Max: -16797616, Received: "
                                + size);
            }
            attribute.set(new MultiPartMessage(channel0, context.byteBufAlloc().buffer(size), parts));
        } else {
            int part = content.readByte() & 0xff;
            if (part != message0.index) {
                throw new CodecException("Received FML MultiPart packet out of order, Expected: "
                        + message0.index + ", Got: " + part);
            }
            int len = content.available() - 1;
            content.readBytes(message0.buffer, message0.offset, len);
            message0.offset += len;
            message0.index++;
            if (message0.index >= message0.parts) {
                final Message message = decode0(context, message0.channel, message0.buffer);
                attribute.set(null);
                return message;
            }
        }
    } else {
        return decode0(context, channel, content);
    }
    return NullMessage.INSTANCE;
}