Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode to json from command line #4024

Closed
KantarBruceAdams opened this issue Dec 11, 2017 · 6 comments
Closed

decode to json from command line #4024

KantarBruceAdams opened this issue Dec 11, 2017 · 6 comments
Assignees
Labels
c++ enhancement inactive Denotes the issue/PR has not seen activity in the last 90 days. protoc

Comments

@KantarBruceAdams
Copy link

Bug: The man page does not state what format is used by the --decode and --encode options
Feature request: Add an option to decode directly to json.

Looking for a way to decode a message into json from the command line I stumbled upon:

https://stackoverflow.com/questions/34952811/is-there-a-definitive-nix-command-line-tool-for-inspecting-protocol-buffers

which mentions the --decode option which at first sight appears to be just what I was looking for.
However the output format is not in fact json but something called "text format" which is undocumented (see #3755).

My use case is that I am writing test cases to check the output of programs that send messages encoded using protocol buffers. I want to convert them to some format that can be analysed easily and add test assertions.
E.g.

ACTUAL=protoc --decode .... | jq .getSomeField
assertEqual "expected foo" "foo" "$ACTUAL"

@KantarBruceAdams
Copy link
Author

note: I observed this on 3.5.0

@imranrazakhan
Copy link

Any update on this feature, is it available now? I couldn't find any option in

#protoc --version
libprotoc 3.6.1

Command:
protoc --decode=my.proto.PkgDiStatus controller.proto</tmp/di.bin

Output:

output is not json

    ups_status {
      low_battery: false
      no_power_out: false
      replace_battery: false
      common_fault: false
    }
    testing_mode: false

@hq6
Copy link

hq6 commented Dec 31, 2021

Since this has been part of the API for a long time, but was never added to the protoc tool, I wrote my own wrapper for this functionality.

https://github.com/hq6/ProtobufJson

@sg-rs
Copy link

sg-rs commented May 24, 2022

@hq6 Thank you very much. It works

@hlopko hlopko assigned sbenzaquen and unassigned mcy May 30, 2023
Copy link

github-actions bot commented Jun 9, 2024

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Jun 9, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ enhancement inactive Denotes the issue/PR has not seen activity in the last 90 days. protoc
Projects
None yet
Development

No branches or pull requests

7 participants