+ TByteArrayList commandsSerialized = new TByteArrayList(4096);
+ byte[] bytes = new byte[8];
+
+ int commandsSize = commands.size();
+ Bytes.writeLE(bytes, 0, commandsSize);
+ commandsSerialized.add(bytes, 0, 4);
+
+ for (Command command : commands) {
+ Bytes.writeLE8(bytes, 0, command.modelId);
+ commandsSerialized.add(bytes);
+ byte[] commandBytes = command.command.getBytes(StandardCharsets.UTF_8);
+ Bytes.writeLE(bytes, 0, commandBytes.length);
+ commandsSerialized.add(bytes, 0, 4);
+ commandsSerialized.add(commandBytes);
+ }
+ return commandsSerialized.toArray();
+ } catch (Exception ee) {
+ // Ok, backwards compatibility required
+ // This is rather slow operation hence the new implementation above
+ try {
+ return SERIALIZER.serialize(this);
+ } catch (IOException e) {
+ LOGGER.error("Could not serialize", e);
+ LOGGER.error("Original exception for new serialisation", ee);
+ throw new RuntimeException(e);
+ }