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%2Futils%2Fstream%2FValueTypes.java;h=1afc73a3c8deb04a471eee01b437ffd06ed769f3;hb=a03f18aaaa755a99e4f504b7f0efac74ab8339ab;hp=3a2d2b49b3ac90c49a7855de4f64d3502d89c2e2;hpb=3c298061e7c22390eaf790aae977decfe0f94ad1;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java index 3a2d2b49b3..1afc73a3c8 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import java.math.BigDecimal; @@ -19,6 +18,9 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; final class ValueTypes { + // The String length threshold beyond which a String should be encoded as bytes + public static final int STRING_BYTES_LENGTH_THRESHOLD = Short.MAX_VALUE / 4; + public static final byte SHORT_TYPE = 1; public static final byte BYTE_TYPE = 2; public static final byte INT_TYPE = 3; @@ -31,6 +33,8 @@ final class ValueTypes { public static final byte BIG_INTEGER_TYPE = 10; public static final byte BIG_DECIMAL_TYPE = 11; public static final byte BINARY_TYPE = 12; + public static final byte NULL_TYPE = 13; + public static final byte STRING_BYTES_TYPE = 14; private static final Map, Byte> TYPES; @@ -43,7 +47,6 @@ final class ValueTypes { b.put(Long.class, Byte.valueOf(LONG_TYPE)); b.put(Boolean.class, Byte.valueOf(BOOL_TYPE)); b.put(QName.class, Byte.valueOf(QNAME_TYPE)); - b.put(YangInstanceIdentifier.class, Byte.valueOf(YANG_IDENTIFIER_TYPE)); b.put(Short.class, Byte.valueOf(SHORT_TYPE)); b.put(BigInteger.class, Byte.valueOf(BIG_INTEGER_TYPE)); b.put(BigDecimal.class, Byte.valueOf(BIG_DECIMAL_TYPE)); @@ -57,16 +60,26 @@ final class ValueTypes { } public static final byte getSerializableType(Object node) { - Preconditions.checkNotNull(node, "node should not be null"); + if(node == null){ + return NULL_TYPE; + } final Byte type = TYPES.get(node.getClass()); if (type != null) { + if(type == STRING_TYPE && ((String) node).length() >= STRING_BYTES_LENGTH_THRESHOLD ){ + return STRING_BYTES_TYPE; + } return type; } + if (node instanceof Set) { return BITS_TYPE; } + if (node instanceof YangInstanceIdentifier) { + return YANG_IDENTIFIER_TYPE; + } + throw new IllegalArgumentException("Unknown value type " + node.getClass().getSimpleName()); } }