Giter Club home page Giter Club logo

protobuf2json-c's People

Contributors

cwalther avatar sannis avatar tony2001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

protobuf2json-c's Issues

JSON encoding for 64 bit numbers.

Google's spec for converting between proto3 and JSON[1] specifies that 64 bit integers should be encoded as JSON strings instead of JSON numbers. I think it would be a good idea to follow that because:

  • Javascript cannot represent all 64 bit integers in its native numerical type.
  • It would allow the full range of uint64 to be used.

However, the spec also states that 64 bit integers encoded as JSON numbers should be accepted (i.e. be permissive). Following that may not be a good idea because it could appear to work when testing with small integers but fail with larger integers that Jansson cannot handle.

Would you be interested in a pull request for this? Do you have any other insight I should be aware of?

[1] https://developers.google.com/protocol-buffers/docs/proto3#json

json2protobuf_object: Type of protobuf_message

Considering the following use case:

    int result;
    char error_string[256] = {0};

    const char *initial_json_string = \
    "{\n"
    "  \"name\": \"John Doe\",\n"
    "  \"id\": 42\n"
    "}";
    Foo__Person* pPerson = NULL;

    result = json2protobuf_string((char *)initial_json_string, JSON_REJECT_DUPLICATES,
        &foo__person__descriptor, (ProtobufCMessage**)&pPerson,
        error_string, sizeof(error_string));
    CPPUNIT_ASSERT_EQUAL(result, 0);
    CPPUNIT_ASSERT(pPerson);
    CPPUNIT_ASSERT_EQUAL(pPerson->id, (int32)42);
    CPPUNIT_ASSERT_STREQUAL(pPerson->name, "John Doe");

    free(pPerson);

Why does the message output buffer require to be passed as (ProtobufCMessage**)? In my opinion it should be either (ProtobufCMessage*) or (void*) for the following reasons:

  • Avoids casting on caller side.
  • Leaves allocation up to caller, i.e. the message can be placed on the stack to avoid the overhead of calloc() in json2protobuf_process_message() for performance reasons. The caller needs to know the exact type anyway, as he is required to pass the message descriptor as well.

error

In section PROTOBUF_C_LABEL_REPEATED (func protobuf2json_process_message) protobuf_values_count is offset for value, not size!
const size_t *protobuf_values_count = (const size_t *)protobuf_value_quantifier;
then you use it as size

        for (j = 0; j < *protobuf_values_count; j++) {
          const char *protobuf_value_repeated = (*(char * const *)protobuf_value) + j * value_size;
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.