26 public const RESULT_OK = 0;
27 public const RESULT_ERROR = 1;
36 private int $requestId,
37 private array $containerInfos = []
39 if($this->result !== self::RESULT_OK && count($this->containerInfos) !== 0){
40 throw new \InvalidArgumentException(
"Container infos must be empty if rejecting the request");
44 public function getResult() : int{ return $this->result; }
46 public function getRequestId() : int{ return $this->requestId; }
51 public static function read(ByteBufferReader $in) : self{
52 $result = Byte::readUnsigned($in);
53 $requestId = CommonTypes::readItemStackRequestId($in);
55 if($result === self::RESULT_OK){
56 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
57 $containerInfos[] = ItemStackResponseContainerInfo::read($in);
60 return new self($result, $requestId, $containerInfos);
63 public function write(ByteBufferWriter $out) : void{
64 Byte::writeUnsigned($out, $this->result);
65 CommonTypes::writeItemStackRequestId($out, $this->requestId);
66 if($this->result === self::RESULT_OK){
67 VarInt::writeUnsignedInt($out, count($this->containerInfos));
68 foreach($this->containerInfos as $containerInfo){
69 $containerInfo->write($out);