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

support serialization to/from human-readable, text-based format #71

Open
timotheecour opened this issue Mar 8, 2016 · 7 comments
Open

Comments

@timotheecour
Copy link
Contributor

http://stackoverflow.com/questions/18873924/what-does-the-protobuf-text-format-look-like
ref: https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format#TextFormat.Parser.WriteLocationsTo.details

I only see json and binary serialization (wire format)

the text format is more convenient than json and is commonly used
would be nice to have it for compatibility

@msoucy
Copy link
Owner

msoucy commented Mar 8, 2016

I've never seen this form of serialization before, it's not mentioned in the docs that I've read. Do analogues exist for other first-party implementations?

@timotheecour
Copy link
Contributor Author

well it's mentioned and described in the above links [including official docs]
it's very commonly used, eg when writing tests, or when writing queries in text proto format
again, it's a more readable syntax than json

at least proto->string direction should be easy.

there are 2 apis for this direction:
toStringShort (output in 1 line)
toStringLong (output in multiple lines with indentation)

and only one for other direction

@timotheecour
Copy link
Contributor Author

@timotheecour
Copy link
Contributor Author

@msoucy ping on this; if it's not on your roadmap, would you have any pointers to get started?

@msoucy
Copy link
Owner

msoucy commented May 18, 2017

It's not on my roadmap... when I started dproto the format didn't even exist.

The main printing code would probably be added to the mixin in attributes.d similar to the serialization code... Though the main logic might be complex enough to warrant being put into another file. The serializeProto function seems like it would have a decent example of how to start adding the code.

@timotheecour
Copy link
Contributor Author

standard text format is actually good but could be better, I propose the following, which handles repeated fields differently in a more json-like way by only putting the name of a repeated field once (or 0) instead of once per repeated element

# dub.prototxt
name: "test1"
sourcePaths: [ "source1", "source2"]
dependencies: [
  { name: "foo", path: "some/path/foo"}
  { name: "bar"}
]

instead of:

name: "test1"
sourcePaths: "source1"
sourcePaths: "source2"
dependencies: { name: "foo", path: "some/path/foo"}
dependencies: { name: "bar"}

Essentially, this is more DRY.

@timotheecour
Copy link
Contributor Author

IIRC i have used a workaround based on using protoc which is not great because it requires shelling out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants