3 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
11 package org.opendaylight.controller.cluster.datastore.node;
13 import org.opendaylight.controller.cluster.datastore.node.utils.PathUtils;
14 import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer;
15 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class NormalizedNodeToNodeCodec {
23 private final SchemaContext ctx;
24 private static final Logger logger = LoggerFactory.getLogger(NormalizedNodeToNodeCodec.class);
26 public NormalizedNodeToNodeCodec(final SchemaContext ctx){
31 public NormalizedNodeMessages.Container encode(YangInstanceIdentifier id, NormalizedNode node){
33 NormalizedNodeMessages.Container.Builder builder = NormalizedNodeMessages.Container.newBuilder();
34 String parentPath = "";
37 parentPath = PathUtils.getParentPath(PathUtils.toString(id));
40 builder.setParentPath(parentPath);
42 builder.setNormalizedNode(NormalizedNodeSerializer.serialize(node));
45 return builder.build();
48 public NormalizedNode<?,?> decode(YangInstanceIdentifier id, NormalizedNodeMessages.Node node){
49 if(node.getIntType() < 0 || node.getSerializedSize() == 0){
52 return NormalizedNodeSerializer.deSerialize(node);