title: How to use a prototbuf map in Python?
body: <p>Given a proto definition </p>
  
  <pre><code>message EndpointResult {
      int32 endpoint_id = 1;
      // property id as key
      map&lt;int32, TimeSeries&gt; properties = 2;
  }
  
  message TimeSeries {
      repeated TimeEntry value = 2;
  }
  
  message TimeEntry {
      int32 time_unit = 1;
      float value = 2;
  }
  </code></pre>
  
  <p>I wish to populate the map in the EndpointResult class. I have tried different approaches suggested in the <a href="https://developers.google.com/protocol-buffers/docs/reference/python-generated?csw=1#map-fields" rel="noreferrer">docs</a> but all raise a error for me. </p>
  
  <p>Setting up a test class</p>
  
  <pre><code>end_point_rslt = nom.EndpointResult()
  end_point_rslt.endpoint_id=0
  
  ts = nom.TimeSeries()
  te = ts.value.add()
  te.time_unit = 0
  te.value = 5.
  </code></pre>
  
  <p>Then trying the different approaches:</p>
  
  <pre><code>end_point_rslt.properties[0] = ts
  </code></pre>
  
  <blockquote>
    <p>ValueError: Direct assignment of submessage not allowed</p>
  </blockquote>
  
  <pre><code>end_point_rslt.properties[0].submessage_field = ts
  </code></pre>
  
  <blockquote>
    <p>AttributeError: Assignment not allowed (no field "submessage_field" in protocol message object).</p>
  </blockquote>
  
  <pre><code>end_point_rslt.properties.get_or_create(0)
  end_point_rslt.properties[0] = ts
  </code></pre>
  
  <blockquote>
    <p>ValueError: Direct assignment of submessage not allowed</p>
  </blockquote>
  
  <pre><code>end_point_rslt.properties.get_or_create(0)
  end_point_rslt.properties[0].submessage_field = ts
  </code></pre>
  
  <blockquote>
    <p>AttributeError: Assignment not allowed (no field "submessage_field" in protocol message object).</p>
  </blockquote>
  
  <pre><code>end_point_rslt.properties = {0 : ts}
  </code></pre>
  
  <blockquote>
    <p>AttributeError: Assignment not allowed to repeated field "properties" in protocol message object.</p>
  </blockquote>
  
  <pre><code>end_point_rslt.properties.get_or_create(0)
  end_point_rslt.properties = {0 : ts}
  </code></pre>
  
  <blockquote>
    <p>TypeError: Can't set composite field</p>
  </blockquote>
  
  <p><strong>Any example of how to use a protocol buffer map in python would be greatly appreciate!</strong> </p>