Add QNameModule coding
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / SodiumNormalizedNodeOutputStreamWriter.java
index c549290f8114e99f7619c93cc0d14196a6ad01df..5f5c0a01fd7fd5a3a9de020a6aa50795776140bb 100644 (file)
@@ -12,6 +12,7 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 
 /**
@@ -30,6 +31,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.Augmentat
  */
 class SodiumNormalizedNodeOutputStreamWriter extends LithiumNormalizedNodeOutputStreamWriter {
     private final Map<AugmentationIdentifier, Integer> aidCodeMap = new HashMap<>();
+    private final Map<QNameModule, Integer> moduleCodeMap = new HashMap<>();
     private final Map<QName, Integer> qnameCodeMap = new HashMap<>();
 
     SodiumNormalizedNodeOutputStreamWriter(final DataOutput output) {
@@ -60,14 +62,29 @@ class SodiumNormalizedNodeOutputStreamWriter extends LithiumNormalizedNodeOutput
     void writeAugmentationIdentifier(final AugmentationIdentifier aid) throws IOException {
         final Integer value = aidCodeMap.get(aid);
         if (value == null) {
-            // Fresh QName, remember it and emit as three strings
+            // Fresh AugmentationIdentifier, remember it and emit as three strings
             aidCodeMap.put(aid, aidCodeMap.size());
             writeByte(TokenTypes.IS_AUGMENT_VALUE);
             super.writeAugmentationIdentifier(aid);
         } else {
-            // We have already seen this QName set: write its code
+            // We have already seen this AugmentationIdentifier: write its code
             writeByte(TokenTypes.IS_AUGMENT_CODE);
             writeInt(value);
         }
     }
+
+    @Override
+    void writeModule(final QNameModule module) throws IOException {
+        final Integer value = moduleCodeMap.get(module);
+        if (value == null) {
+            // Fresh QNameModule, remember it and emit as three strings
+            moduleCodeMap.put(module, moduleCodeMap.size());
+            writeByte(TokenTypes.IS_MODULE_VALUE);
+            super.writeModule(module);
+        } else {
+            // We have already seen this QNameModule: write its code
+            writeByte(TokenTypes.IS_MODULE_CODE);
+            writeInt(value);
+        }
+    }
 }