Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1632

C++ JsonEncoder dosen't close braces of objects

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 1.7.7
    • 1.7.7
    • c++
    • Ubuntu 12.04, gcc 4.6.4

    • C++

    Description

      Please see the example.

      Expected output is:

      result: '{"re":100.23,"im":105.77}'
      

      Actual output is:

      result: '{"re":100.23,"im":105.77'
      
      json_encode_example.cc
      #include <fstream>
      #include <iostream>
      
      #include <avro/Compiler.hh>
      #include <avro/Encoder.hh>
      #include <avro/Stream.hh>
      #include <avro/ValidSchema.hh>
      
      #include "cpx.hh"
      
      int
      main()
      {
          static size_t CHUNK_SIZE = 8 * 1024;
      
          std::ifstream ifs("examples/cpx.json");
      
          avro::ValidSchema cpxSchema;
          avro::compileJsonSchema(ifs, cpxSchema);
      
          std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream(CHUNK_SIZE);
          avro::EncoderPtr e = avro::jsonEncoder(cpxSchema);
          e->init(*out);
          c::cpx c1;
          c1.re = 100.23;
          c1.im = 105.77;
          avro::encode(*e, c1);
          out->flush();
          std::cout << "out->byteCount(): " << out->byteCount() << std::endl;
      
          std::auto_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
          avro::StreamReader streamReader(*in);
          uint8_t jsonBytes[CHUNK_SIZE];
          size_t length = CHUNK_SIZE;
          streamReader.readBytes(jsonBytes, length);
          std::cout << "in->byteCount(): " << in->byteCount() << std::endl;
      
          std::cout << "result: \'" << jsonBytes << "\'" << std::endl;
          for (size_t i = 0; i < 30; i += 1) {
              printf("jsonBytes[%02zu]: 0x%02X (%c)\n", i, (unsigned char) jsonBytes[i], jsonBytes[i]);
          }
      
          return 0;
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Heye Heye Vöcking
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: