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

oneof support #4

Closed
ka3a4ok opened this issue Jul 28, 2015 · 10 comments
Closed

oneof support #4

ka3a4ok opened this issue Jul 28, 2015 · 10 comments

Comments

@ka3a4ok
Copy link

ka3a4ok commented Jul 28, 2015

Is there any planes to add oneof support?

@k-bx
Copy link
Owner

k-bx commented Jul 28, 2015 via email

@bitc
Copy link

bitc commented Aug 7, 2015

I might be interested in implementing this. @k-bx could you give any pointers on how to go about implementing this, for someone unfamiliar with the codebase? Which parts would need to be modified? How much knowledge of the wire protocol will I need?

Any guidance you could give would be appreciated

@k-bx
Copy link
Owner

k-bx commented Aug 7, 2015

@bitc great to know you'd be willing to give it a try!

I'll be honest with you, I'm not familiar with codebase at all, I also don't know much about protobuf protocol. I took maintainership somewhat recently just to keep package alive (update dependencies, merge with fork etc.). So I think you'll be on your own here (if you'll feel comfortable with code-base, I'd be happy to make you a co-maintainer).

But I will certainly do in-depth code-review when the feature is ready before merging it :)

@stiell
Copy link

stiell commented Nov 23, 2015

Any progress on this? If not, I might give it a try. I'm not very familiar with protocol buffers or this package, but from reading the spec I have an idea of what I think oneof should look like in Haskell.

@wavewave
Copy link
Contributor

I am also very interested in oneof implementation, too!

@wavewave
Copy link
Contributor

I've started implementing oneof on oneof branch in http://github.com/wavewave/protocol-buffers. Until now, I succeeded in parsing a proto file with oneof (See this sample file ). Creating haskell module from this is not done yet, but I will continue to work on it. Stay tuned!

@stiell
Copy link

stiell commented Dec 13, 2015

I started on this, but got a little stuck on how to represent oneofs in Reflections.hs

Here's how I think oneofs might look in Haskell. Example:

message Message {
    oneof foo {
        string name = 4;
        SubMessage sub_message = 9;
    }
}

This might (after #5 is implemented) generate something like:

data Foo = Name Utf8
         | SubMessage SomeOtherModule.SubMessage
data Message = Message { foo :: Maybe Foo }

and possibly also functions name :: Message -> Maybe Utf8 and subMessage :: Message -> Maybe SomeOtherModule.SubMessage.

@wavewave
Copy link
Contributor

yes. that's the goal (using sum type in haskell to represent oneof).

The original protobuf implementation for sum types is quite ugly (the fields in oneof has a oneof_index flag to specify which oneof it belongs to, i.e. it is not defined in tree-like structure, but as ownership graphs). Since we reuse descriptor.proto from the original protobuf library, we need to keep this structure somehow (at least, until parsing), so the reinterpretation as haskell sum type is not very transparent as it seems.

I now think I figured out how to tackle this problem. It's a little aggressive change in the code base, though.

@wavewave
Copy link
Contributor

I've succeeded in oneof implementation up to instance of TextMsg (textGet, textPut). Oneof is implemented as a sum type. Now I move on to final binary wire serialization!

@wavewave
Copy link
Contributor

Binary (wire) encoding/decoding for oneof is implemented! Tested between haskell and C++ (code generated from protoc). I will clean the code up and make a pull request soon.

This was referenced Dec 27, 2015
@k-bx k-bx closed this as completed Jan 10, 2016
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

5 participants