2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore.messages;
11 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
12 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
13 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Encoded;
14 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 public class WriteData extends ModifyData {
21 public static final Class<ShardTransactionMessages.WriteData> SERIALIZABLE_CLASS =
22 ShardTransactionMessages.WriteData.class;
24 public WriteData(YangInstanceIdentifier path, NormalizedNode<?, ?> data, SchemaContext schemaContext) {
25 super(path, data, schemaContext);
29 public Object toSerializable() {
30 Encoded encoded = new NormalizedNodeToNodeCodec(schemaContext).encode(path, data);
31 return ShardTransactionMessages.WriteData.newBuilder()
32 .setInstanceIdentifierPathArguments(encoded.getEncodedPath())
33 .setNormalizedNode(encoded.getEncodedNode().getNormalizedNode()).build();
36 public static WriteData fromSerializable(Object serializable, SchemaContext schemaContext){
37 ShardTransactionMessages.WriteData o = (ShardTransactionMessages.WriteData) serializable;
38 Decoded decoded = new NormalizedNodeToNodeCodec(schemaContext).decode(
39 o.getInstanceIdentifierPathArguments(), o.getNormalizedNode());
40 return new WriteData(decoded.getDecodedPath(), decoded.getDecodedNode(), schemaContext);