- public static ShardDataTreeSnapshot deserialize(final byte[] bytes) throws IOException {
- /**
- * Unfortunately versions prior to Boron did not include any way to evolve the snapshot format and contained
- * only the raw data stored in the datastore. Furthermore utilities involved do not check if the array is
- * completely consumed, which has a nasty side-effect when coupled with the fact that PayloadVersion writes
- * a short value.
- *
- * Since our versions fit into a single byte, we end up writing the 0 as the first byte, which would be
- * interpreted as 'not present' by the old snapshot format, which uses writeBoolean/readBoolean. A further
- * complication is that readBoolean interprets any non-zero value as true, hence we cannot use a wild value
- * to cause it to fail.
- */
- if (isLegacyStream(bytes)) {
- return deserializeLegacy(bytes);
- }
-
- try {
- try (final InputStream is = new ByteArrayInputStream(bytes)) {
- try (final DataInputStream dis = new DataInputStream(is)) {
- final ShardDataTreeSnapshot ret = AbstractVersionedShardDataTreeSnapshot.deserialize(dis);
-
- // Make sure we consume all bytes, otherwise something went very wrong
- final int bytesLeft = dis.available();
- if (bytesLeft != 0) {
- throw new IOException("Deserialization left " + bytesLeft + " in the buffer");
- }
+ public static @NonNull ShardSnapshotState deserialize(final ObjectInput in) throws IOException {
+ final ShardSnapshotState ret = AbstractVersionedShardDataTreeSnapshot.versionedDeserialize(in);