-
Notifications
You must be signed in to change notification settings - Fork 8
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
Ability to convert a native protobuf object from/to clojure wrapper object? #33
Comments
You should be able to do this by:
This will, of course, require that you have done all the rest of the setup in your Clojure project (point to your protobuf schema, compiled to java, etc.). Caveat: I said should ;-) I've not tried this at all; let's see how it goes. If what I outlined above doesn't work, we'll figure something out. Once we get something working, we should be able to update the API to make it a little easier to do the conversion ... reduce the number of steps/amount of setup ... I'm already getting some ideas ;-) Keep me posted! |
Just did a little playing around ... this approach won't work as outlined for schemas that have defined required fields ... still poking at it, though. |
Thanks for you prompt reply!
I had an issue with enums ( will look into that later ). -- Just seen that you have noticed the required issue as well -- |
I may have a solution; testing something now ... |
Okay, I have something in place that I've only tested in the REPL and with just one compiled protobuf class. I've pushed the latest up to Clojars:
Once we get this hammered out, I'll add tests and docs for the new capability. Here's what I did to test:
Let me know how this goes, and how any other testing of different protobufs/compiled classes go ... |
Basically, this involved updating the constructor to allow creating a new Clojure protobuf from a byte-array ( Keep in mind that right now, this project only explicitly supports the |
I'll explore adding |
I've added support for creating protobuf instance from Using the same approach as given above, here's how you can create an instance from a [protobuf.dev] λ=> (def phones [(protobuf/create AddressBookProtos$Person$PhoneNumber
{:number "555-1212" :type :home})
(protobuf/create AddressBookProtos$Person$PhoneNumber
{:number "555-1213" :type :mobile})
(protobuf/create AddressBookProtos$Person$PhoneNumber
{:number "555-1214" :type :work})])
[protobuf.dev] λ=> (def phone-bytes (protobuf/->bytes (first phones)))
[protobuf.dev] λ=> (import com.google.protobuf.CodedInputStream)
[protobuf.dev] λ=> (def s (com.google.protobuf.CodedInputStream/newInstance phone-bytes))
[protobuf.dev] λ=> (protobuf/create AddressBookProtos$Person$PhoneNumber s) {:number "555-1212", :type :home} And here's how you create one from [protobuf.dev] λ=> (def s (new java.io.ByteArrayInputStream phone-bytes))
[protobuf.dev] λ=> (protobuf/create AddressBookProtos$Person$PhoneNumber s) {:number "555-1212", :type :home} |
Thanks again for this next level response time! |
works for me as well, thanks :) |
Hi, is there a way to somehow convert from and to a native protobuf object?
I want to (->
read native protobuf objects from parquet ( via org.apache.parquet.proto/ProtoReadSupport)
Transform them into clojusc/protobuf based objects
Manipulate them as edn via this promising lib :)
Build native protobuf objects from the transformed values
Write to parquet ( via ProtoWriteSupport )
)
I am not sure if this approach is sound, but currently I see no way to convert to/from the native protobuf object.
In other words, the following blog/project demonstrates the approach, and it even references this library(in its older form?) as an alternative. But it will not really work without some conversion - as it rely on Kryo serialisation and really expects the native protobuf object and not the wrapper object:
https://adambard.com/blog/parquet-protobufs-spark/
https://github.com/adambard/sparkquet/blob/master/src/clj/sparkquet/core.clj
The actual objects are highly nested/repeated and manipulating them as edn would be much simpler.
Sorry if I am missing something basic here.
The text was updated successfully, but these errors were encountered: