X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2Futils%2Fserialization%2FValueSerializer.java;h=f562d8b35dd09995ac03d9ce2b3f4436518c8c6f;hp=6a843f57c7718fb76911e90649b7194e3b6db0bb;hb=2d2f9c82e47c09a09da090e153b084a426e0aa57;hpb=1b8f7c7beaed83797320686bebddd536637aed9a diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java index 6a843f57c7..f562d8b35d 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java @@ -8,15 +8,15 @@ package org.opendaylight.controller.cluster.datastore.node.utils.serialization; -import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory; -import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils; -import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; - +import com.google.protobuf.ByteString; import java.math.BigDecimal; import java.math.BigInteger; import java.util.HashSet; import java.util.Set; +import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory; +import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils; +import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; public class ValueSerializer { public static void serialize(NormalizedNodeMessages.Node.Builder builder, @@ -27,17 +27,19 @@ public class ValueSerializer { builder.setInstanceIdentifierValue( InstanceIdentifierUtils.toSerializable((YangInstanceIdentifier) value, context)); } else if(value instanceof Set) { - Set set = (Set) value; - if(!set.isEmpty()){ - for(Object o : set){ - if(o instanceof String){ + Set set = (Set) value; + if (!set.isEmpty()) { + for (Object o : set) { + if (o instanceof String) { builder.addBitsValue(o.toString()); } else { throw new IllegalArgumentException("Expected value type to be Bits but was : " + - value.toString()); + value.toString()); } } } + } else if(value instanceof byte[]){ + builder.setBytesValue(ByteString.copyFrom((byte[]) value)); } else { builder.setValue(value.toString()); } @@ -47,7 +49,27 @@ public class ValueSerializer { QNameSerializationContext context, Object value){ builder.setType(ValueType.getSerializableType(value).ordinal()); - builder.setValue(value.toString()); + + if(value instanceof YangInstanceIdentifier) { + builder.setInstanceIdentifierValue( + InstanceIdentifierUtils.toSerializable((YangInstanceIdentifier) value, context)); + } else if(value instanceof Set) { + Set set = (Set) value; + if (!set.isEmpty()) { + for (Object o : set) { + if (o instanceof String) { + builder.addBitsValue(o.toString()); + } else { + throw new IllegalArgumentException("Expected value type to be Bits but was : " + + value.toString()); + } + } + } + } else if(value instanceof byte[]){ + builder.setBytesValue(ByteString.copyFrom((byte[]) value)); + } else { + builder.setValue(value.toString()); + } } public static Object deSerialize(QNameDeSerializationContext context, @@ -56,13 +78,24 @@ public class ValueSerializer { return InstanceIdentifierUtils.fromSerializable( node.getInstanceIdentifierValue(), context); } else if(node.getIntValueType() == ValueType.BITS_TYPE.ordinal()){ - return new HashSet(node.getBitsValueList()); + return new HashSet<>(node.getBitsValueList()); + } else if(node.getIntValueType() == ValueType.BINARY_TYPE.ordinal()){ + return node.getBytesValue().toByteArray(); } return deSerializeBasicTypes(node.getIntValueType(), node.getValue()); } public static Object deSerialize(QNameDeSerializationContext context, NormalizedNodeMessages.PathArgumentAttribute attribute) { + + if(attribute.getType() == ValueType.YANG_IDENTIFIER_TYPE.ordinal()){ + return InstanceIdentifierUtils.fromSerializable( + attribute.getInstanceIdentifierValue(), context); + } else if(attribute.getType() == ValueType.BITS_TYPE.ordinal()){ + return new HashSet<>(attribute.getBitsValueList()); + } else if(attribute.getType() == ValueType.BINARY_TYPE.ordinal()){ + return attribute.getBytesValue().toByteArray(); + } return deSerializeBasicTypes(attribute.getType(), attribute.getValue()); }