/*
 * This file was automatically generated by sel-utils and
 * released under the MIT License.
 * 
 * License: https://github.com/sel-project/sel-utils/blob/master/LICENSE
 * Repository: https://github.com/sel-project/sel-utils
 * Generated from https://github.com/sel-project/sel-utils/blob/master/xml/protocol/java338.xml
 */
package sul.protocol.java338.clientbound;

import sul.utils.*;

public class SetSlot extends Packet {

	public static final int ID = (int)22;

	public static final boolean CLIENTBOUND = true;
	public static final boolean SERVERBOUND = false;

	@Override
	public int getId() {
		return ID;
	}

	public byte window;
	public short slot;
	public sul.protocol.java338.types.Slot item;

	public SetSlot() {}

	public SetSlot(byte window, short slot, sul.protocol.java338.types.Slot item) {
		this.window = window;
		this.slot = slot;
		this.item = item;
	}

	@Override
	public int length() {
		return item.length() + 4;
	}

	@Override
	public byte[] encode() {
		this._buffer = new byte[this.length()];
		this.writeVaruint(ID);
		this.writeBigEndianByte(window);
		this.writeBigEndianShort(slot);
		this.writeBytes(item.encode());
		return this.getBuffer();
	}

	@Override
	public void decode(byte[] buffer) {
		this._buffer = buffer;
		this.readVaruint();
		window=readBigEndianByte();
		slot=readBigEndianShort();
		item=new sul.protocol.java338.types.Slot(); item._index=this._index; item.decode(this._buffer); this._index=item._index;
	}

	public static SetSlot fromBuffer(byte[] buffer) {
		SetSlot ret = new SetSlot();
		ret.decode(buffer);
		return ret;
	}

	@Override
	public String toString() {
		return "SetSlot(window: " + this.window + ", slot: " + this.slot + ", item: " + this.item.toString() + ")";
	}

}