|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Aternos\Nbt\Deserializer; |
| 4 | + |
| 5 | +use Aternos\Nbt\NbtFormat; |
| 6 | +use pocketmine\utils\Binary; |
| 7 | + |
| 8 | +class BedrockEditionNetworkNbtDeserializer extends BedrockEditionNbtDeserializer |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @inheritDoc |
| 12 | + */ |
| 13 | + public function getFormat(): int |
| 14 | + { |
| 15 | + return NbtFormat::BEDROCK_EDITION_NETWORK; |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * @inheritDoc |
| 20 | + */ |
| 21 | + public function readLengthPrefix(): DeserializerIntReadResult |
| 22 | + { |
| 23 | + $reader = $this->getReader(); |
| 24 | + $raw = $reader->read(5); |
| 25 | + $offset = 0; |
| 26 | + $value = Binary::readVarInt($raw, $offset); |
| 27 | + $reader->returnData(substr($raw, $offset)); |
| 28 | + return new DeserializerIntReadResult($value, substr($raw, 0, $offset)); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @inheritDoc |
| 33 | + */ |
| 34 | + public function readStringLengthPrefix(): DeserializerIntReadResult |
| 35 | + { |
| 36 | + $reader = $this->getReader(); |
| 37 | + $raw = $reader->read(5); |
| 38 | + $offset = 0; |
| 39 | + $value = Binary::readUnsignedVarInt($raw, $offset); |
| 40 | + $reader->returnData(substr($raw, $offset)); |
| 41 | + return new DeserializerIntReadResult($value, substr($raw, 0, $offset)); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @inheritDoc |
| 46 | + */ |
| 47 | + public function readInt(): DeserializerIntReadResult |
| 48 | + { |
| 49 | + $reader = $this->getReader(); |
| 50 | + $raw = $reader->read(5); |
| 51 | + $offset = 0; |
| 52 | + $value = Binary::readVarInt($raw, $offset); |
| 53 | + $reader->returnData(substr($raw, $offset)); |
| 54 | + return new DeserializerIntReadResult($value, substr($raw, 0, $offset)); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @inheritDoc |
| 59 | + */ |
| 60 | + public function readLong(): DeserializerIntReadResult |
| 61 | + { |
| 62 | + $reader = $this->getReader(); |
| 63 | + $raw = $reader->read(10); |
| 64 | + $offset = 0; |
| 65 | + $value = Binary::readVarLong($raw, $offset); |
| 66 | + $reader->returnData(substr($raw, $offset)); |
| 67 | + return new DeserializerIntReadResult($value, substr($raw, 0, $offset)); |
| 68 | + } |
| 69 | +} |
0 commit comments