import org.opendaylight.controller.cluster.datastore.node.utils.stream.InvalidNormalizedNodeStreamException;
import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput;
import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader;
-import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeOutputStreamWriter;
import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
* @author Thomas Pantelis
*/
public final class SerializationUtils {
- public static final ThreadLocal<NormalizedNodeOutputStreamWriter> REUSABLE_WRITER_TL = new ThreadLocal<>();
- public static final ThreadLocal<NormalizedNodeInputStreamReader> REUSABLE_READER_TL = new ThreadLocal<>();
+ public static final ThreadLocal<NormalizedNodeDataOutput> REUSABLE_WRITER_TL = new ThreadLocal<>();
+ public static final ThreadLocal<NormalizedNodeDataInput> REUSABLE_READER_TL = new ThreadLocal<>();
- public static interface Applier<T> {
+ public interface Applier<T> {
void apply(T instance, YangInstanceIdentifier path, NormalizedNode<?, ?> node);
}
private static NormalizedNodeDataOutput streamWriter(DataOutput out) throws IOException {
- NormalizedNodeOutputStreamWriter streamWriter = REUSABLE_WRITER_TL.get();
+ NormalizedNodeDataOutput streamWriter = REUSABLE_WRITER_TL.get();
if(streamWriter == null) {
- streamWriter = new NormalizedNodeOutputStreamWriter(out);
+ streamWriter = NormalizedNodeInputOutput.newDataOutput(out);
}
return streamWriter;
}
private static NormalizedNodeDataInput streamReader(DataInput in) throws IOException {
- NormalizedNodeInputStreamReader streamWriter = REUSABLE_READER_TL.get();
- if(streamWriter == null) {
- streamWriter = new NormalizedNodeInputStreamReader(in);
+ NormalizedNodeDataInput streamReader = REUSABLE_READER_TL.get();
+ if(streamReader == null) {
+ streamReader = new NormalizedNodeInputStreamReader(in);
}
- return streamWriter;
+ return streamReader;
}
public static void serializePathAndNode(YangInstanceIdentifier path, NormalizedNode<?, ?> node,
}
public static NormalizedNode<?, ?> deserializeNormalizedNode(byte [] bytes) {
- NormalizedNode<?, ?> node = null;
try {
- node = tryDeserializeNormalizedNode(new DataInputStream(new ByteArrayInputStream(bytes)));
+ return tryDeserializeNormalizedNode(new DataInputStream(new ByteArrayInputStream(bytes)));
} catch(InvalidNormalizedNodeStreamException e) {
// Probably from legacy protobuf serialization - try that.
try {
NormalizedNodeMessages.Node serializedNode = NormalizedNodeMessages.Node.parseFrom(bytes);
- node = new NormalizedNodeToNodeCodec(null).decode(serializedNode);
+ return new NormalizedNodeToNodeCodec(null).decode(serializedNode);
} catch (InvalidProtocolBufferException e2) {
throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
}
} catch (IOException e) {
throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
}
-
- return node;
}
public static byte [] serializeNormalizedNode(NormalizedNode<?, ?> node) {