/** * Writes the given snapshot to the out stream. One should always use this method to write * snapshots out, rather than directly calling {@link #writeSnapshot(DataOutputView)}. * * <p>The snapshot written with this method can be read via {@link #readVersionedSnapshot(DataInputView, ClassLoader)}. */ static void writeVersionedSnapshot(DataOutputView out, TypeSerializerSnapshot<?> snapshot) throws IOException { out.writeUTF(snapshot.getClass().getName()); out.writeInt(snapshot.getCurrentVersion()); snapshot.writeSnapshot(out); }
/** * Serialize an (avro)TypeSerializerSnapshot and deserialize it. */ private static <T> AvroSerializerSnapshot<T> roundTrip(TypeSerializerSnapshot<T> original) throws IOException { // writeSnapshot(); DataOutputSerializer out = new DataOutputSerializer(1024); original.writeSnapshot(out); // init AvroSerializerSnapshot<T> restored = new AvroSerializerSnapshot<>(); // readSnapshot(); DataInputView in = new DataInputDeserializer(out.wrapAsByteBuffer()); restored.readSnapshot(restored.getCurrentVersion(), in, original.getClass().getClassLoader()); return restored; }
/** * Writes the given snapshot to the out stream. One should always use this method to write * snapshots out, rather than directly calling {@link #writeSnapshot(DataOutputView)}. * * <p>The snapshot written with this method can be read via {@link #readVersionedSnapshot(DataInputView, ClassLoader)}. */ static void writeVersionedSnapshot(DataOutputView out, TypeSerializerSnapshot<?> snapshot) throws IOException { out.writeUTF(snapshot.getClass().getName()); out.writeInt(snapshot.getCurrentVersion()); snapshot.writeSnapshot(out); }