Move Neon SR2 tokens into its own class 63/84563/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 20 Sep 2019 17:42:15 +0000 (19:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Sep 2019 08:45:32 +0000 (10:45 +0200)
Same as with base Lithium tokens, these can create confusion about
where they are used. Make sure we encapsulate them in their own
class, so no confusion ensues.

JIRA: CONTROLLER-1919
Change-Id: I197b9118a5d9a09562db0a899bb6b8dc0dfae28b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2NormalizedNodeInputStreamReader.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2NormalizedNodeOutputStreamWriter.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2Tokens.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/TokenTypes.java

index fb38fa4..80ec1b0 100644 (file)
@@ -42,9 +42,9 @@ final class NeonSR2NormalizedNodeInputStreamReader extends AbstractLithiumDataIn
     public QName readQName() throws IOException {
         final byte valueType = readByte();
         switch (valueType) {
-            case TokenTypes.IS_QNAME_CODE:
+            case NeonSR2Tokens.IS_QNAME_CODE:
                 return codedQName(readInt());
-            case TokenTypes.IS_QNAME_VALUE:
+            case NeonSR2Tokens.IS_QNAME_VALUE:
                 return rawQName();
             default:
                 throw new IOException("Unhandled QName value type " + valueType);
@@ -55,9 +55,9 @@ final class NeonSR2NormalizedNodeInputStreamReader extends AbstractLithiumDataIn
     AugmentationIdentifier readAugmentationIdentifier() throws IOException {
         final byte valueType = readByte();
         switch (valueType) {
-            case TokenTypes.IS_AUGMENT_CODE:
+            case NeonSR2Tokens.IS_AUGMENT_CODE:
                 return codedAugmentId(readInt());
-            case TokenTypes.IS_AUGMENT_VALUE:
+            case NeonSR2Tokens.IS_AUGMENT_VALUE:
                 return rawAugmentId();
             default:
                 throw new IOException("Unhandled QName value type " + valueType);
@@ -70,9 +70,9 @@ final class NeonSR2NormalizedNodeInputStreamReader extends AbstractLithiumDataIn
         // to do that we inter-mingle with readQName()
         final byte valueType = readByte();
         switch (valueType) {
-            case TokenTypes.IS_QNAME_CODE:
+            case NeonSR2Tokens.IS_QNAME_CODE:
                 return codedNodeIdentifier(readInt());
-            case TokenTypes.IS_QNAME_VALUE:
+            case NeonSR2Tokens.IS_QNAME_VALUE:
                 return rawNodeIdentifier();
             default:
                 throw new IOException("Unhandled QName value type " + valueType);
@@ -82,9 +82,9 @@ final class NeonSR2NormalizedNodeInputStreamReader extends AbstractLithiumDataIn
     private QNameModule readModule() throws IOException {
         final byte valueType = readByte();
         switch (valueType) {
-            case TokenTypes.IS_MODULE_CODE:
+            case NeonSR2Tokens.IS_MODULE_CODE:
                 return codedModule(readInt());
-            case TokenTypes.IS_MODULE_VALUE:
+            case NeonSR2Tokens.IS_MODULE_VALUE:
                 return rawModule();
             default:
                 throw new IOException("Unhandled QName value type " + valueType);
index 43bcc34..010b220 100644 (file)
@@ -49,11 +49,11 @@ final class NeonSR2NormalizedNodeOutputStreamWriter extends AbstractLithiumDataO
         if (value == null) {
             // Fresh QName, remember it and emit as three strings
             qnameCodeMap.put(qname, qnameCodeMap.size());
-            writeByte(TokenTypes.IS_QNAME_VALUE);
+            writeByte(NeonSR2Tokens.IS_QNAME_VALUE);
             defaultWriteQName(qname);
         } else {
             // We have already seen this QName: write its code
-            writeByte(TokenTypes.IS_QNAME_CODE);
+            writeByte(NeonSR2Tokens.IS_QNAME_CODE);
             writeInt(value);
         }
     }
@@ -64,11 +64,11 @@ final class NeonSR2NormalizedNodeOutputStreamWriter extends AbstractLithiumDataO
         if (value == null) {
             // Fresh AugmentationIdentifier, remember it and emit as three strings
             aidCodeMap.put(aid, aidCodeMap.size());
-            writeByte(TokenTypes.IS_AUGMENT_VALUE);
+            writeByte(NeonSR2Tokens.IS_AUGMENT_VALUE);
             defaultWriteAugmentationIdentifier(aid);
         } else {
             // We have already seen this AugmentationIdentifier: write its code
-            writeByte(TokenTypes.IS_AUGMENT_CODE);
+            writeByte(NeonSR2Tokens.IS_AUGMENT_CODE);
             writeInt(value);
         }
     }
@@ -79,11 +79,11 @@ final class NeonSR2NormalizedNodeOutputStreamWriter extends AbstractLithiumDataO
         if (value == null) {
             // Fresh QNameModule, remember it and emit as three strings
             moduleCodeMap.put(module, moduleCodeMap.size());
-            writeByte(TokenTypes.IS_MODULE_VALUE);
+            writeByte(NeonSR2Tokens.IS_MODULE_VALUE);
             defaultWriteModule(module);
         } else {
             // We have already seen this QNameModule: write its code
-            writeByte(TokenTypes.IS_MODULE_CODE);
+            writeByte(NeonSR2Tokens.IS_MODULE_CODE);
             writeInt(value);
         }
     }
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2Tokens.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2Tokens.java
new file mode 100644 (file)
index 0000000..9126747
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.node.utils.stream;
+
+/**
+ * Tokens used in Neon SR2 encoding. Note that Neon SR2 builds on top of Lithium, hence the token values must never
+ * overlap.
+ */
+final class NeonSR2Tokens {
+    static final byte IS_QNAME_CODE = 4;
+    static final byte IS_QNAME_VALUE = 5;
+    static final byte IS_AUGMENT_CODE = 6;
+    static final byte IS_AUGMENT_VALUE = 7;
+    static final byte IS_MODULE_CODE = 8;
+    static final byte IS_MODULE_VALUE = 9;
+
+    private NeonSR2Tokens() {
+
+    }
+}
index 8fc7d6d..43082af 100644 (file)
@@ -23,12 +23,4 @@ final class TokenTypes {
      * dictionary, too.
      */
     static final short NEON_SR2_VERSION = 2;
-
-    // Tokens supported in NEON_SR2_VERSION
-    static final byte IS_QNAME_CODE = 4;
-    static final byte IS_QNAME_VALUE = 5;
-    static final byte IS_AUGMENT_CODE = 6;
-    static final byte IS_AUGMENT_VALUE = 7;
-    static final byte IS_MODULE_CODE = 8;
-    static final byte IS_MODULE_VALUE = 9;
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.