Coder Social home page Coder Social logo

Comments (2)

azeey avatar azeey commented on August 11, 2024

Looks like there might be an option to tell Protobuf to include default value fields for the JSON ouptut https://stackoverflow.com/questions/31021797/protobuf-doesnt-serialize-default-values and https://protobuf.dev/reference/cpp/api-docs/google.protobuf.util.json_util/#JsonPrintOptions. Would you be up for submitting a PR?

I'm afraid it's not trivial to do the same for DebugString.

from gz-transport.

jrutgeer avatar jrutgeer commented on August 11, 2024

@azeey My main reason to report the issue was just to make sure that this is normal behavior, and not a symptom of some other, underlying problem.

And indeed it turns out to be default and well documented behavior of protobuf, see this application note and this discussion.

There's an optional keyword since protoc 3.12 (flag --experimental_allow_proto3_optional) and 3.15 (no longer experimental), to indicate Explicit Presence.

I did a test per these implementation instructions:

  • Add this to Generator.hh:

uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
}

  • Add optional keyword to float data in float.proto

  • Pass --experimental_allow_proto3_optional flag to protoc during build (I put it in a script as I don't know a better way):
    colcon build --merge-install --packages-select gz-msgs9 --cmake-args -DPROTOC_EXEC=/tmp/protoc-exp

This works fine:

gz topic -t /foo -m gz.msgs.Float -p 'data:0.0'

gz topic -e -t /foo
data: 0

So that seems a possible resolution.

Anyway, as there is no real functional impact (other than the 0 values not being echoed), I close this issue.

from gz-transport.

Related Issues (20)

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.