/*
 * 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/bedrock160.xml
 */
package sul.protocol.bedrock160.play;

import sul.utils.*;

public class SetEntityLink extends Packet {

	public static final int ID = (int)41;

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

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

	// action
	public static final byte REMOVE = (byte)0;
	public static final byte ADD = (byte)1;

	public long vehicle;
	public long passenger;
	public byte action;

	public SetEntityLink() {}

	public SetEntityLink(long vehicle, long passenger, byte action) {
		this.vehicle = vehicle;
		this.passenger = passenger;
		this.action = action;
	}

	@Override
	public int length() {
		return Buffer.varlongLength(vehicle) + Buffer.varlongLength(passenger) + 2;
	}

	@Override
	public byte[] encode() {
		this._buffer = new byte[this.length()];
		this.writeVaruint(ID);
		this.writeVarlong(vehicle);
		this.writeVarlong(passenger);
		this.writeLittleEndianByte(action);
		return this.getBuffer();
	}

	@Override
	public void decode(byte[] buffer) {
		this._buffer = buffer;
		this.readVaruint();
		vehicle=this.readVarlong();
		passenger=this.readVarlong();
		action=readLittleEndianByte();
	}

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

	@Override
	public String toString() {
		return "SetEntityLink(vehicle: " + this.vehicle + ", passenger: " + this.passenger + ", action: " + this.action + ")";
	}

}