All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jnngl.server.protocol.ServerboundFramePacket Maven / Gradle / Ivy

There is a newer version: 0.10.2b
Show newest version
package com.jnngl.server.protocol;

import com.jnngl.server.Server;
import com.jnngl.server.exception.TooSmallPacketException;
import io.netty.buffer.ByteBuf;

public class ServerboundFramePacket extends Packet {
    @Override
    public byte getPacketID() {
        return (byte)0xC0;
    }

    @Override
    public void writeData(ByteBuf buf) {
        buf.writeShort(id);
        buf.writeBytes(compressedData);
    }

    @Override
    public void readData(ByteBuf buf, int length) throws Exception {
        if(length < 2) throw new TooSmallPacketException(length, 2);
        id = buf.readShort();
        compressedData = new byte[buf.readableBytes()];
        buf.readBytes(compressedData, 0, compressedData.length);
        if(compressedData.length != length-2) {
            if(Server.DEBUG)
                System.err.println("Received incomplete frame buffer");
            compressedData = null;
        }
    }

    @Override
    public int getLength() {
        if(compressedData == null) return 2;
        return 2+compressedData.length;
    }

    public short id;
    public byte[] compressedData;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy