X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2FNormalizedNodeToNodeCodec.java;h=4e76e37fa25c179ac3f2b196f97ee389261a8c97;hb=refs%2Fchanges%2F68%2F10268%2F9;hp=17bdb36e569612ef513a787e010aeb8583167984;hpb=c74d5c2399e500fe3e690edc8cee497b1cb6f867;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodec.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodec.java index 17bdb36e56..4e76e37fa2 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodec.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodec.java @@ -10,9 +10,9 @@ package org.opendaylight.controller.cluster.datastore.node; -import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages; import org.opendaylight.controller.cluster.datastore.node.utils.PathUtils; -import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer; +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; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -29,45 +29,27 @@ public class NormalizedNodeToNodeCodec { } public NormalizedNodeMessages.Container encode(YangInstanceIdentifier id, NormalizedNode node){ + + NormalizedNodeMessages.Container.Builder builder = NormalizedNodeMessages.Container.newBuilder(); String parentPath = ""; if(id != null){ - parentPath = PathUtils.getParentPath(id.toString()); + parentPath = PathUtils.getParentPath(PathUtils.toString(id)); } + builder.setParentPath(parentPath); + if(node != null) { + builder.setNormalizedNode(NormalizedNodeSerializer.serialize(node)); + } - NormalizedNodeToProtocolBufferNode encoder = new NormalizedNodeToProtocolBufferNode(); - encoder.encode(parentPath, node); - - return encoder.getContainer(); - - + return builder.build(); } public NormalizedNode decode(YangInstanceIdentifier id, NormalizedNodeMessages.Node node){ - NodeToNormalizedNodeBuilder currentOp = NodeToNormalizedNodeBuilder.from(ctx); - - for(YangInstanceIdentifier.PathArgument pathArgument : id.getPathArguments()){ - currentOp = currentOp.getChild(pathArgument); - } - - QName nodeType = null; - - if(id.getPath().size() < 1){ - nodeType = null; - } else { - final YangInstanceIdentifier.PathArgument pathArgument = id.getPath().get(id.getPath().size() - 1); - if(pathArgument instanceof YangInstanceIdentifier.AugmentationIdentifier){ - nodeType = null; - } else { - nodeType = pathArgument.getNodeType(); - } - } - if((node != null)&& (!node.getType().isEmpty())){ - return currentOp.normalize(nodeType, node); - } else{ - return null; - } + if(node.getIntType() < 0 || node.getSerializedSize() == 0){ + return null; + } + return NormalizedNodeSerializer.deSerialize(node); }