From 89cfad684aa11320b575550da9c48a2db5b7d0f8 Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Fri, 22 May 2015 01:10:45 +0200
Subject: [PATCH] WiP: intentions partially implemented in C, Java
 (typedefparser broken), and python

---
 compiler/2014/Annotations.jrag                |  2 +
 compiler/2014/FlatSignature.jrag              |  2 +-
 compiler/2014/Java_CodeGen.jrag               | 23 +++++++++
 compiler/2014/Refactoring.jrag                |  4 +-
 compiler/2014/Signature.jrag                  | 14 +++---
 compiler/2014/TypeCheck.jrag                  |  7 ++-
 lib/c/2014/labcomm2014_decoder.c              | 12 ++++-
 lib/c/2014/labcomm2014_encoder.c              | 10 ++--
 .../test/test_labcomm_generated_encoding.c    |  4 +-
 .../control/labcomm2014/DecoderChannel.java   | 24 +++++++++
 .../control/labcomm2014/EncoderChannel.java   | 16 ++++++
 .../control/labcomm2014/SampleDispatcher.java | 10 ++--
 .../lth/control/labcomm2014/TypeBinding.java  |  8 +++
 .../se/lth/control/labcomm2014/TypeDef.java   | 50 ++++++++++++-------
 .../control/labcomm2014/TypeDefParser.java    |  2 +-
 lib/python/labcomm2014/LabComm.py             | 46 +++++++----------
 16 files changed, 166 insertions(+), 68 deletions(-)

diff --git a/compiler/2014/Annotations.jrag b/compiler/2014/Annotations.jrag
index 25e145d..3c7275c 100644
--- a/compiler/2014/Annotations.jrag
+++ b/compiler/2014/Annotations.jrag
@@ -48,6 +48,8 @@ aspect SigAnnotations {
             }
     };
 
+    syn int Decl.getNumIntentions() = getTypeInstance().sortedIntentions().getNumChild();
+
    syn List<Intention> TypeInstance.sortedIntentions() {
        List<Intention> res = new List<Intention>();
 
diff --git a/compiler/2014/FlatSignature.jrag b/compiler/2014/FlatSignature.jrag
index 42e768a..637f01f 100644
--- a/compiler/2014/FlatSignature.jrag
+++ b/compiler/2014/FlatSignature.jrag
@@ -78,7 +78,7 @@ aspect FlatSignature {
   public void Field.flatSignature(SignatureList list) {
     debugAnnotations(this.getName()+".Field.flatSignature");
     list.addIntentions(intentions(), "Field: "+getIntentionString());
-    list.addString(getName(), signatureComment());
+//    list.addString(getName(), signatureComment());
     getDataType().flatSignature(list);
   }
 
diff --git a/compiler/2014/Java_CodeGen.jrag b/compiler/2014/Java_CodeGen.jrag
index 3578002..d1af545 100644
--- a/compiler/2014/Java_CodeGen.jrag
+++ b/compiler/2014/Java_CodeGen.jrag
@@ -473,6 +473,7 @@ aspect Java_Class {
   }
 
   public void Decl.Java_emitIntentions(Java_env env){
+    env.println("private static int numIntentions = " +getNumIntentions() +";");
     env.println("private static byte[] intentions = new byte[] {");
     env.indent();
     byte[] data = getIntentionBytes();
@@ -583,6 +584,28 @@ aspect Java_Class {
     env.unindent();
     env.println("}");
     env.println();
+    env.println("/** return the outermost intentions. */");
+    env.println("public byte[] getIntentionBytes() {");
+    env.indent();
+    if(isSample) {
+        env.println("return intentions;");
+    } else {
+        env.println("return new byte[0];");
+    }
+    env.unindent();
+    env.println("}");
+    env.println();
+    env.println("/** return the number of intentions. */");
+    env.println("public int getNumIntentions() {");
+    env.indent();
+    if(isSample) {
+        env.println("return numIntentions;");
+    } else {
+        env.println("return 0;");
+    }
+    env.unindent();
+    env.println("}");
+    env.println();
 //    env.println("public void encodeSignature(Encoder e) throws IOException{");
 //    env.indent();
 //    env.println("emitSignature(e);");
diff --git a/compiler/2014/Refactoring.jrag b/compiler/2014/Refactoring.jrag
index 2e66939..6e2860b 100644
--- a/compiler/2014/Refactoring.jrag
+++ b/compiler/2014/Refactoring.jrag
@@ -7,12 +7,12 @@ aspect Refactoring {
 
     public Annotations Annotations.addName(String n) {
         //XXX TODO: check if name already exists
-        addAnnotation(new Annotation("",n.getBytes()));
+        addAnnotation(new Intention("",n.getBytes()));
         return this;
     }
 
     public Field.Field(TypeInstance t) {
-        this(t.getDataType(), t.getAnnotations().addName(t.getName()));
+        this(t.getDataType(), t.getAnnotations());
     }
 
     public TypeInstance.TypeInstance(DataType t, String n, Annotations a) {
diff --git a/compiler/2014/Signature.jrag b/compiler/2014/Signature.jrag
index bdad9bc..d04b029 100644
--- a/compiler/2014/Signature.jrag
+++ b/compiler/2014/Signature.jrag
@@ -289,6 +289,7 @@ aspect Signature {
     public void TypeInstance.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
 //              debugAnnotations(this.getName());
 //              list.addString(inst.getIntentionString(), "intention string");
+                list.addIntentions(intentionSet(), "intentions");
                 getDataType().genSigLineForDecl(list, decl, this);
     }
 
@@ -351,12 +352,13 @@ aspect Signature {
         list.add(null, "}");
     }
 
-    public void Field.genSigLineForDecl(SignatureList list, boolean decl,  ASTNode inst) {
-        list.addString(getName(), signatureComment());
-        super.genSigLineForDecl(list, decl, inst);
-        //TODOintent
-        //getDataType().genSigLineForDecl(list, decl, inst);
-    }
+//    public void Field.genSigLineForDecl(SignatureList list, boolean decl,  ASTNode inst) {
+//        //XXX make intention
+//        list.addString(getName(), signatureComment());
+//        super.genSigLineForDecl(list, decl, inst);
+//        //TODOintent
+//       //getDataType().genSigLineForDecl(list, decl, inst);
+//    }
 
     public void IntegerLiteral.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
         list.addInt(Integer.parseInt(getValue()), null);
diff --git a/compiler/2014/TypeCheck.jrag b/compiler/2014/TypeCheck.jrag
index 3e6dd9c..8efa4d0 100644
--- a/compiler/2014/TypeCheck.jrag
+++ b/compiler/2014/TypeCheck.jrag
@@ -44,8 +44,11 @@ aspect AnnotationCheck {
   public void ASTNode.annotationCheck() {}
 
   public void TypeDecl.annotationCheck() {
-    if(getTypeInstance().hasIntentions()) {
-      error("TypeDecl " + getName() + " has intentions. (Not allowed for typedefs)");
+    Iterator<Intention> it = getTypeInstance().intentions().iterator();;
+    while(it.hasNext()) {
+     if(!it.next().getKey().equals("")) {
+       error("TypeDecl " + getName() + " has intentions. (Not allowed for typedefs)");
+     }
     }
   }
 }
diff --git a/lib/c/2014/labcomm2014_decoder.c b/lib/c/2014/labcomm2014_decoder.c
index 181c53b..8e7bf1a 100644
--- a/lib/c/2014/labcomm2014_decoder.c
+++ b/lib/c/2014/labcomm2014_decoder.c
@@ -161,7 +161,7 @@ static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind)
    int numInts = labcomm2014_read_byte(d->reader);
 
    if(numInts != 1) {
-       printf("WARNING! #intentions != 1, this will probably crash\n");
+       printf("WARNING! #intentions %d != 1, this will probably crash\n", numInts);
    }
   //XXX temporary kludge for intentions
   //assume only one intention: the name
@@ -482,6 +482,16 @@ static void decode_raw_type_def(
   struct labcomm2014_raw_type_def v;
   v.index = labcomm2014_read_packed32(r);
   if (r->error < 0) { goto out; }
+  {
+  int numInts = labcomm2014_read_byte(r);
+
+  if(numInts != 1) {
+    printf("WARNING! #intentions %d != 1, this will probably crash\n", numInts);
+  }
+  //XXX temporary kludge for intentions
+  //assume only one intention: the name
+  labcomm2014_read_packed32(r); // assume the empty key (i.e., name)
+  }
   v.name  = labcomm2014_read_string(r);
   if (r->error < 0) { goto free_name; }
   v.length = labcomm2014_read_packed32(r);
diff --git a/lib/c/2014/labcomm2014_encoder.c b/lib/c/2014/labcomm2014_encoder.c
index 3897915..91d5870 100644
--- a/lib/c/2014/labcomm2014_encoder.c
+++ b/lib/c/2014/labcomm2014_encoder.c
@@ -302,15 +302,15 @@ static int internal_reg_type(
   if (err != 0) { result = err; goto out; }
 
   int sig_size = calc_sig_encoded_size(e, signature);
-  int len =  labcomm2014_size_packed32(index) +
-             labcomm2014_size_string(signature->name) +
-             labcomm2014_size_packed32(sig_size) +
-              sig_size;
+  int len = (labcomm2014_size_packed32(index) +
+            TODO_sizeof_intentions(signature) +
+            labcomm2014_size_packed32(signature->size) +
+            sig_size);
 
   labcomm2014_write_packed32(e->writer, LABCOMM_TYPE_DEF);
   labcomm2014_write_packed32(e->writer, len);
   labcomm2014_write_packed32(e->writer, index);
-  labcomm2014_write_string(e->writer, signature->name);
+  TODO_encode_intentions(e, signature);
   labcomm2014_write_packed32(e->writer, sig_size);
   do_write_signature(e, signature, LABCOMM2014_FALSE);
 
diff --git a/lib/c/2014/test/test_labcomm_generated_encoding.c b/lib/c/2014/test/test_labcomm_generated_encoding.c
index 023bdf6..6485f78 100644
--- a/lib/c/2014/test/test_labcomm_generated_encoding.c
+++ b/lib/c/2014/test/test_labcomm_generated_encoding.c
@@ -214,8 +214,8 @@ int main(void)
   labcomm2014_encoder_register_generated_encoding_V(encoder);
   labcomm2014_encoder_register_generated_encoding_V(encoder);
   EXPECT({ 0x02, 0x08, VARIABLE(0), 0x01, 0x00, 0x01, 'V', 0x02, 0x11, 0x00,
-           0x04, 0x08, VARIABLE(1), 0x03, 'v', '_', 't', 0x02, 0x11, 0x00,
-           0x04, 0x05, VARIABLE(2), 0x01, 'V', 0x01, VARIABLE(1),
+           0x04, 0x0a, VARIABLE(1), 0x01, 0x00, 0x03, 'v', '_', 't', 0x02, 0x11, 0x00,
+           0x04, 0x07, VARIABLE(2), 0x01, 0x00, 0x01, 'V', 0x01, VARIABLE(1),
            0x05, 0x02, VARIABLE(0), VARIABLE(2) });
 
   labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
diff --git a/lib/java/se/lth/control/labcomm2014/DecoderChannel.java b/lib/java/se/lth/control/labcomm2014/DecoderChannel.java
index 013dc68..ca5d6ae 100644
--- a/lib/java/se/lth/control/labcomm2014/DecoderChannel.java
+++ b/lib/java/se/lth/control/labcomm2014/DecoderChannel.java
@@ -18,6 +18,14 @@ public class DecoderChannel implements Decoder {
 
   private void processSampleDef() throws IOException {
     int index = decodePacked32();
+    int numIntentions = decodePacked32();
+    if(numIntentions != 1) {
+        System.out.println("WARNING: #intentions == "+numIntentions);
+    }
+    int keylen = decodePacked32();
+    if(keylen != 0) {
+        System.out.println("WARNING: keylen == "+keylen);
+    }
     String name = decodeString();
     int signature_length = decodePacked32();
     byte[] signature = new byte[signature_length];
@@ -27,6 +35,14 @@ public class DecoderChannel implements Decoder {
 
   private void processSampleRef() throws IOException {
     int index = decodePacked32();
+    int numIntentions = decodePacked32();
+    if(numIntentions != 1) {
+        System.out.println("WARNING: #intentions == "+numIntentions);
+    }
+    int keylen = decodePacked32();
+    if(keylen != 0) {
+        System.out.println("WARNING: keylen == "+keylen);
+    }
     String name = decodeString();
     int signature_length = decodePacked32();
     byte[] signature = new byte[signature_length];
@@ -39,6 +55,14 @@ public class DecoderChannel implements Decoder {
            processSample(Constant.TYPE_DEF);
       } catch(Exception ex) {
        int idx = decodePacked32();
+    int numIntentions = decodePacked32();
+    if(numIntentions != 1) {
+        System.out.println("WARNING: #intentions == "+numIntentions);
+    }
+    int keylen = decodePacked32();
+    if(keylen != 0) {
+        System.out.println("WARNING: keylen == "+keylen);
+    }
        String name = decodeString();
        int siglen = decodePacked32();
        for(int i=0; i<siglen; i++) {
diff --git a/lib/java/se/lth/control/labcomm2014/EncoderChannel.java b/lib/java/se/lth/control/labcomm2014/EncoderChannel.java
index b6c25bb..94e8b0b 100644
--- a/lib/java/se/lth/control/labcomm2014/EncoderChannel.java
+++ b/lib/java/se/lth/control/labcomm2014/EncoderChannel.java
@@ -46,7 +46,15 @@ public class EncoderChannel implements Encoder {
         int index = sample_def_registry.add(dispatcher);
         begin(dispatcher.getTypeDeclTag());
         encodePacked32(index);
+        //HERE BE DRAGONS! numintentions does not include name
+//        encodePacked32(dispatcher.getNumIntentions()+1);
+        encodePacked32(1);
+        encodePacked32(0); // the empty key == name
         encodeString(dispatcher.getName());
+//        byte[] intentions = dispatcher.getIntentionBytes();
+//        for (int k = 0 ; k < intentions.length ; k++) {
+//            encodeByte(intentions[k]);
+//        }
         byte[] signature = dispatcher.getSignature();
         encodePacked32(signature.length);
         for (int i = 0 ; i < signature.length ; i++) {
@@ -92,6 +100,10 @@ public class EncoderChannel implements Encoder {
 
             begin(Constant.TYPE_DEF);
             encodePacked32(index);
+            //HERE BE DRAGONS! numintentions does not include name
+//          encodePacked32(dispatcher.getNumIntentions()+1);
+            encodePacked32(1);
+            encodePacked32(0); // the empty key == name
             encodeString(dispatcher.getName());
             encodePacked32(b.length);
             for(int i = 0; i<b.length; i++) {
@@ -123,6 +135,10 @@ public class EncoderChannel implements Encoder {
     int index = sample_ref_registry.add(dispatcher);
     begin(Constant.SAMPLE_REF);
     encodePacked32(index);
+     //HERE BE DRAGONS! numintentions does not include name
+//        encodePacked32(dispatcher.getNumIntentions()+1);
+    encodePacked32(1);
+    encodePacked32(0); // the empty key == name
     encodeString(dispatcher.getName());
     byte[] signature = dispatcher.getSignature();
     encodePacked32(signature.length);
diff --git a/lib/java/se/lth/control/labcomm2014/SampleDispatcher.java b/lib/java/se/lth/control/labcomm2014/SampleDispatcher.java
index 0d6b8b4..c6784df 100644
--- a/lib/java/se/lth/control/labcomm2014/SampleDispatcher.java
+++ b/lib/java/se/lth/control/labcomm2014/SampleDispatcher.java
@@ -3,13 +3,17 @@ package se.lth.control.labcomm2014;
 import java.io.IOException;
 
 public interface SampleDispatcher <T extends SampleType>{
-    
+
   public Class<T> getSampleClass();
-    
+
   public String getName();
 
   public byte[] getSignature();
 
+  public int getNumIntentions();
+
+  public byte[] getIntentionBytes();
+
   public void decodeAndHandle(Decoder decoder,
 			      SampleHandler handler) throws Exception;
 
@@ -23,7 +27,7 @@ public interface SampleDispatcher <T extends SampleType>{
    *  by encoder.register.
    *  TODO: refactor types, moving this to a super-interface
    *  applicable to both type and sample defs.
-   */ 
+   */
   public byte getTypeDeclTag();
 }
 
diff --git a/lib/java/se/lth/control/labcomm2014/TypeBinding.java b/lib/java/se/lth/control/labcomm2014/TypeBinding.java
index 47b33d5..74ef1f3 100644
--- a/lib/java/se/lth/control/labcomm2014/TypeBinding.java
+++ b/lib/java/se/lth/control/labcomm2014/TypeBinding.java
@@ -77,6 +77,14 @@ public class TypeBinding implements BuiltinType {
       return null; // not used for matching
     }
 
+  public int getNumIntentions() {
+      return 0;
+  }
+
+  public byte[] getIntentionBytes() {
+     return null; // not used for matching
+  }
+
     public void encodeTypeDef(Encoder e, int index) throws IOException{
       throw new Error("Should not be called");
     }
diff --git a/lib/java/se/lth/control/labcomm2014/TypeDef.java b/lib/java/se/lth/control/labcomm2014/TypeDef.java
index 494365c..78fbef9 100644
--- a/lib/java/se/lth/control/labcomm2014/TypeDef.java
+++ b/lib/java/se/lth/control/labcomm2014/TypeDef.java
@@ -24,7 +24,7 @@ public class TypeDef implements BuiltinType {
   public String toString() {
      return getName();
   }
- 
+
   public byte[] getSignature() {
     return signature;
   }
@@ -39,32 +39,32 @@ public class TypeDef implements BuiltinType {
   public interface Handler extends SampleHandler {
     public void handle_TypeDef(TypeDef value) throws Exception;
   }
-  
+
   public static void register(Decoder d, Handler h) throws IOException {
     d.register(Dispatcher.singleton(), h);
   }
-  
+
   public static void register(Encoder e) throws IOException {
     register(e,false);
   }
-  
+
   public static void register(Encoder e, boolean sendMetaData) throws IOException {
     throw new IOException("cannot send TypeDefs");
   }
-  
+
  static class Dispatcher implements SampleDispatcher<TypeDef> {
-    
+
     private static Dispatcher singleton;
-    
+
     public synchronized static Dispatcher singleton() {
       if(singleton==null) singleton=new Dispatcher();
       return singleton;
     }
-    
+
     public Class<TypeDef> getSampleClass() {
       return TypeDef.class;
     }
-    
+
     public String getName() {
       return "TypeDef";
     }
@@ -72,41 +72,49 @@ public class TypeDef implements BuiltinType {
     public byte getTypeDeclTag() {
       throw new Error("Should not be called");
     }
-    
+
     public boolean isSample() {
       throw new Error("Should not be called");
     }
     public boolean hasStaticSignature() {
       throw new Error("Should not be called");
     }
-    
+
     /** return the flat signature. Intended use is on decoder side */
     public byte[] getSignature() {
       return null; // not used for matching
     }
-    
+
+    public int getNumIntentions() {
+        return 0;
+    }
+
+    public byte[] getIntentionBytes() {
+        return new byte[0];
+    }
+
     public void encodeTypeDef(Encoder e, int index) throws IOException{
       throw new Error("Should not be called");
     }
-    
+
 //    public boolean canDecodeAndHandle() {
 //      return true;
 //    }
-    
+
     public void decodeAndHandle(Decoder d,
                                 SampleHandler h) throws Exception {
       ((Handler)h).handle_TypeDef(TypeDef.decode(d));
     }
-    
+
     public boolean hasDependencies() {
         return false;
     }
   }
-  
+
   public static void encode(Encoder e, TypeDef value) throws IOException {
     throw new Error("Should not be called");
   }
-  
+
   protected TypeDef() {
   }
 
@@ -119,6 +127,14 @@ public class TypeDef implements BuiltinType {
   public static TypeDef decode(Decoder d) throws IOException {
     TypeDef result;
     int index = d.decodePacked32();
+    int numIntentions = d.decodePacked32();
+    if(numIntentions != 1) {
+        System.out.println("WARNING: #intentions == "+numIntentions);
+    }
+    int keylen = d.decodePacked32();
+    if(keylen != 0) {
+        System.out.println("WARNING: keylen == "+keylen);
+    }
     String name = d.decodeString();
     int siglen= d.decodePacked32();
     byte sig[] = new byte[siglen];
diff --git a/lib/java/se/lth/control/labcomm2014/TypeDefParser.java b/lib/java/se/lth/control/labcomm2014/TypeDefParser.java
index e063cb4..4a04106 100644
--- a/lib/java/se/lth/control/labcomm2014/TypeDefParser.java
+++ b/lib/java/se/lth/control/labcomm2014/TypeDefParser.java
@@ -547,7 +547,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
         String getCurrentName() {
             return current.getName();
         }
-        
+
         String decodeIntentions() throws IOException {
             int n = decodePacked32() & 0xffffffff;
             if(n==0) return "";
diff --git a/lib/python/labcomm2014/LabComm.py b/lib/python/labcomm2014/LabComm.py
index 5a279f1..9fdaf79 100644
--- a/lib/python/labcomm2014/LabComm.py
+++ b/lib/python/labcomm2014/LabComm.py
@@ -401,9 +401,9 @@ class sampledef_or_sampleref_or_typedef(type_decl):
         encoder.encode_type(self.type_index)
         with length_encoder(encoder) as e1:
             e1.encode_type(self.get_index(encoder))
-            e1.encode_string(self.name)
+            # XXX: temporary hack for intentions
+            e1.encode_empty_intentions(self.name)
             with length_encoder(e1) as e2:
-                self.encode_empty_intentions(e2)
                 self.decl.encode_decl(e2)
 
     def encode(self, encoder, value):
@@ -411,10 +411,11 @@ class sampledef_or_sampleref_or_typedef(type_decl):
 
     def decode_decl(self, decoder):
         index = decoder.decode_type_number()
-        name = decoder.decode_string()
+         # XXX: temporary hack for intentions
+         #      assume the name is the only intention
+        name = decoder.decode_intentions()
         if usePacketLength(decoder.version):
             length = decoder.decode_packed32()
-        self.decode_intentions(decoder)
         decl = decoder.decode_decl()
         result = self.__class__.__new__(self.__class__)
         result.__init__(name=name, decl=decl)
@@ -456,12 +457,6 @@ class sample_def(sampledef_or_sampleref_or_typedef):
     def rename(self, name):
         return sample_def(name=name, decl=self.decl)
 
-    def decode_intentions(self, d):
-        return d.decode_string()
-
-    def encode_empty_intentions(self, e):
-        e.encode_empty_intentions()
-
 class sample_ref(sampledef_or_sampleref_or_typedef):
     type_index = i_SAMPLE_REF
     type_name = 'sample_ref'
@@ -474,12 +469,6 @@ class sample_ref(sampledef_or_sampleref_or_typedef):
         else:
             self.sample = sample
 
-    def decode_intentions(self, d):
-        return d.decode_string()
-
-    def encode_empty_intentions(self, e):
-        e.encode_empty_intentions()
-
     def get_index(self, encoder):
         return encoder.ref_to_index[self.sample]
 
@@ -490,12 +479,6 @@ class typedef(sampledef_or_sampleref_or_typedef):
     type_index = i_TYPE_DEF
     type_name = 'typedef'
 
-    def decode_intentions(self, d):
-        pass
-
-    def encode_empty_intentions(self, e):
-        pass
-
     def encode_decl(self, encoder):
         self.decl.encode_decl(encoder)
 
@@ -647,8 +630,7 @@ class struct(type_decl):
         encoder.encode_type(i_STRUCT)
         encoder.encode_packed32(len(self.field))
         for (name, decl) in self.field:
-            encoder.encode_empty_intentions()
-            encoder.encode_string(name)
+            encoder.encode_empty_intentions(name)
             encoder.encode_type_number(decl)
 
     def encode(self, encoder, obj):
@@ -663,8 +645,7 @@ class struct(type_decl):
         n_field = decoder.decode_packed32()
         field = []
         for i in range(n_field):
-            intentions = decoder.decode_intentions()
-            name = decoder.decode_string()
+            name = decoder.decode_intentions()
             decl = decoder.decode_decl()
             field.append((name, decl))
         return struct(field)
@@ -891,9 +872,11 @@ class Encoder(Codec):
 	self.encode_packed32(len(s));
 	self.pack("%ds" % len(s),s)
 
-    def encode_empty_intentions(self):
+    def encode_empty_intentions(self, name):
 #        pass
+        self.encode_packed32(1)
         self.encode_string("")
+        self.encode_string(name)
 
 class Decoder(Codec):
     def __init__(self, reader, version=DEFAULT_VERSION):
@@ -1027,7 +1010,14 @@ class Decoder(Codec):
         return self.index_to_ref.get(index, None)
 
     def decode_intentions(self):
-        return self.decode_string()
+        numIntentions = self.decode_packed32()
+        name = ""
+        for i in range(numIntentions):
+            key = self.decode_string()
+            val = self.decode_string()
+            if key=="":
+                name = val
+        return name
 
 class signature_reader:
     def __init__(self, signature):
-- 
GitLab