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

C++ JsonEncoder dosen't close braces of objects

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 1.7.7
    • Fix Version/s: 1.7.7
    • Component/s: c++
    • Labels:
    • Environment:

      Ubuntu 12.04, gcc 4.6.4

    • Tags:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: