Merge "Bug 2265: Use streaming for DeleteData message"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / SerializationUtils.java
index 8404a6e6d81f99788b5dcba2dca5aa1b4ba2c763..3f2125746300f5350ae42be63d10e6b761840a2e 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWrit
  * @author Thomas Pantelis
  */
 public final class SerializationUtils {
+
     public static interface Applier<T> {
         void apply(T instance, YangInstanceIdentifier path, NormalizedNode<?, ?> node);
     }
@@ -78,4 +79,23 @@ public final class SerializationUtils {
 
         return null;
     }
+
+    public static void serializePath(YangInstanceIdentifier path, DataOutput out) {
+        Preconditions.checkNotNull(path);
+        try {
+            NormalizedNodeOutputStreamWriter streamWriter = new NormalizedNodeOutputStreamWriter(out);
+            streamWriter.writeYangInstanceIdentifier(path);
+        } catch (IOException e) {
+            throw new IllegalArgumentException(String.format("Error serializing path {}", path), e);
+        }
+    }
+
+    public static YangInstanceIdentifier deserializePath(DataInput in) {
+        try {
+            NormalizedNodeInputStreamReader streamReader = new NormalizedNodeInputStreamReader(in);
+            return streamReader.readYangInstanceIdentifier();
+        } catch (IOException e) {
+            throw new IllegalArgumentException("Error deserializing path", e);
+        }
+    }
 }