-
Notifications
You must be signed in to change notification settings - Fork 451
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
Read access to NameMap mapping. #731
Comments
Can you explain a little more what the use for this is? Are you trying to transform something from a proto into another format? i.e. - what is proto bringing to the table in the first place? The |
I'm trying to migrate from a proprietary binary format to Protobuf without breaking an API contract. Legacy client code is also sending and receiving NSDictionary through the module I am working on. Using Protobuf schemas with field names matching the dictionary keys and going through JSON nearly allowed me to just switch out the serialization format. But when parsing a Protobuf Message to a dictionary going through JSON, type information is lost. Example:
Writing a custom Visitor (that could even skip JSON) seemed to be the natural way to solve this problem. However, writing my own Visitor does not allow me to access the property names like the internal JSON Encoder can. |
I have a similar use case. I am receiving a domain object, which is defined in proto and encoded to JSON on my server and receiving it on the iOS side as a To do this, I am implementing a custom It would be helpful to get access to |
If the server and client are using protos, why not just use the built in support for binary or json? i.e. - why do you need a custom decoder? A custom decoder sorta implies you are doing your own format thing, in which case, nothing would seem to guarantee the name transforms done by protos would match your custom encoding, no? |
In my case, I have limited control over the transport layer and its Swift SDK. I am using proto3 standard JSON encoding on the write side, but, unfortunately, I receive a Swift dictionary on the read side. Specifically, I am using firestore (gcp docs/firebase docs). My main motivation to use protobuf is to increase type-safety across my client and server codebases. |
The the keys match, then you might want to try serialize the JSON again (to bytes) and feed it to SwiftProtobuf, no custom decoder needed, so it could be list total code for you to maintain. |
Agreed in theory... That idea works for many cases, however some types encoded in the |
@mickeyreiss, I'm in the same boat as you (also for Firebase). Interesting that we independently reached the same conclusion. Perhaps that implies something. What did you end up doing here? |
@nwparker we ended up writing our own code generation that keeps different languages' firestore models in sync based on a schema. |
Thanks for the reply, @mickeyreiss. Let me know if you guys plan to ever share any of that code out. It sounds useful. For now I've decided to just go with writing back and forth via JSON since it's easiest to implement. Although it is sad to lose some types in Firebase. For now I'm only storing Timestamps and I suppose it's fine to store them as ISO8601 strings (they preserve sorting this way anyways) |
@nwparker that plan makes sense. In retrospect, I’ve noticed that firestore does use protos behind the scenes. They hide this fact in their client SDKs. It might make sense to construct a Feel free to contact me directly regarding our codegen if you’re interested. |
Hei, @mickeyreiss same situation is here, I am want to custom the code generation for my own, like generate some extentsion which has method like |
(My advice is about 1 year out of date, so please take it with a grain of salt.)
I’m essence, there is no metaprogramming in the runtime. All of the type mapping occurs at compile time. |
You should not modify However, you can use |
Are there any plans on allowing the read access to NameMap mapping? As many other stated, this would be extremely valuable for debugging and logging purposes. For now, we need to use workarounds like the reflection based approach which unnecessarily complicates the extremely simple task (getting the value's description) by the order of magnitude, is less performant and much more error-prone. |
nothing planned at the moment. What's your usecase for needing the data? |
@thomasvl Sorry for the very late reply. We have an analytics system that uses proto messages under the hood. The idea is that clients should be able to inspect recorded events in the debug menu. |
Hello,
I have to write a custom encoder from Protobuf to something else. I've noticed that the Visitor protocol is public so I was planning to create a custom Visitor that will do the encoding.
My problem is that I don't have any way to get the name of the field using the fieldNumber that I receive in the visitor call. That's because the
names(for number: Int) -> Names?
is internal.Would it make sense to add a public method
names(for number: Int) -> String?
that can be used for writing custom encoders/visitors?Thanks!
The text was updated successfully, but these errors were encountered: