Skip to content

Commit b6501cc

Browse files
committed
use short types in JSON
HAP spec allows shortening UUIDs if they're well known Apple ones doing this drastically reduces response sizes
1 parent a6972ca commit b6501cc

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public abstract class BaseCharacteristic<T> implements Characteristic {
2222
private final Logger logger = LoggerFactory.getLogger(BaseCharacteristic.class);
2323

2424
private final String type;
25+
private final String shortType;
2526
private final String format;
2627
private final boolean isWritable;
2728
private final boolean isReadable;
@@ -46,6 +47,7 @@ public BaseCharacteristic(
4647
}
4748

4849
this.type = type;
50+
this.shortType = this.type.replaceAll("^0*([0-9a-fA-F]+)-0000-1000-8000-0026BB765291$", "$1");
4951
this.format = format;
5052
this.isWritable = isWritable;
5153
this.isReadable = isReadable;
@@ -94,7 +96,7 @@ protected CompletableFuture<JsonObjectBuilder> makeBuilder(int instanceId) {
9496
JsonObjectBuilder builder =
9597
Json.createObjectBuilder()
9698
.add("iid", instanceId)
97-
.add("type", type)
99+
.add("type", shortType)
98100
.add("perms", perms.build())
99101
.add("format", format)
100102
.add("ev", false)

src/main/java/com/beowulfe/hap/impl/json/AccessoryController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ public HttpResponse listing() throws Exception {
6565
}
6666

6767
private CompletableFuture<JsonObject> toJson(Service service, int interfaceId) throws Exception {
68+
String shortType =
69+
service.getType().replaceAll("^0*([0-9a-fA-F]+)-0000-1000-8000-0026BB765291$", "$1");
6870
JsonObjectBuilder builder =
69-
Json.createObjectBuilder().add("iid", ++interfaceId).add("type", service.getType());
71+
Json.createObjectBuilder().add("iid", ++interfaceId).add("type", shortType);
7072
List<Characteristic> characteristics = service.getCharacteristics();
7173
Collection<CompletableFuture<JsonObject>> characteristicFutures =
7274
new ArrayList<>(characteristics.size());

0 commit comments

Comments
 (0)