title: How to use apache avro GenericRecord for dynamic data?
body: <p>I want to use Apache Avro to serialize my data, my client is written in C++, and my server is written in Java. </p>
  
  <ol>
  <li><p>My server java code looks like this:</p>
  
  <pre><code>Schema scm = new Schema.Parser().parse("....shcema String.....");
  ByteArrayInputStream inputStream = new ByteArrayInputStream(record.array());
  Decoder coder = new DecoderFactory().directBinaryDecoder(inputStream, null);
  GenericDatumReader&lt;GenericRecord&gt; reDatumReader = new GenericDatumReader&lt;GenericRecord&gt;(scm);
  try {
      GenericRecord result = (GenericRecord)reDatumReader.read(null, coder);
              //here! the result "name", "num_groups" is empty!
      System.out.println(result.get("name")+"   "+result.get("num_groups"));
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } 
  </code></pre></li>
  <li><p>And my client code:</p>
  
  <pre><code>std::string schemaDescript ="....shcema String.....";
  
  std::stringstream rsStream(schemaDescript);
  avro::ValidSchema rSchema;
  avro::compileJsonSchema(rsStream, rSchema);
  avro::EncoderPtr encoder = avro::binaryEncoder();
  std::auto_ptr&lt;avro::OutputStream&gt; oStream = avro::memoryOutputStream();
  encoder-&gt;init(*oStream);   
  avro::GenericDatum rData(rSchema);
  avro::GenericRecord sReord = rData.value&lt;avro::GenericRecord&gt;();
  sReord.setFieldAt(0, avro::GenericDatum("i am nice"));
  sReord.setFieldAt(1, avro::GenericDatum(1));
  sReord.setFieldAt(2, avro::GenericDatum(12));
  sReord.setFieldAt(3, avro::GenericDatum(13));
  
  avro::GenericWriter gwriter(rSchema, encoder);
  gwriter.write(rData);
  oStream-&gt;flush();
  
  std::auto_ptr&lt;avro::InputStream&gt; inSt = avro::memoryInputStream(*oStream);
  avro::StreamReader instReader(*inSt);
  
  size_t outputLen = oStream-&gt;byteCount();
  uint8_t* theByteData = new uint8_t[outputLen];
  instReader.hasMore();
  instReader.readBytes(theByteData, outputLen);
  </code></pre></li>
  </ol>
  
  <p>I send the <code>theByteData</code> to the server, the code works (no exception), but the result is empty, can anyone tell me what's wrong? </p>
  
  <p>And why in Java we get value with key: <code>result.get("name")</code>; but in C++ we get value with index: <code>record.fieldAt(0).value&lt;string&gt;()</code>. If I can't get value with the string key, how to match the index to string key?</p>