1 package com.irtimaled.bbor.common.messages;
3 import com.irtimaled.bbor.common.BoundingBoxType;
4 import com.irtimaled.bbor.common.models.AbstractBoundingBox;
5 import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
6 import com.irtimaled.bbor.common.models.Coords;
8 class BoundingBoxDeserializer {
9 static AbstractBoundingBox deserialize(PayloadReader reader) {
10 if (!reader.isReadable(2)) return null;
12 char type = reader.readChar();
13 return type == 'S' ? deserializeStructure(reader) : null;
16 private static AbstractBoundingBox deserializeStructure(PayloadReader reader) {
17 BoundingBoxType type = BoundingBoxType.getByNameHash(reader.readInt());
18 if (type == null) return null;
19 Coords minCoords = reader.readCoords();
20 Coords maxCoords = reader.readCoords();
21 return BoundingBoxCuboid.from(minCoords, maxCoords, type);