Skip to content

(WIP) Introduce Thrift.Serializable #441

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fishcakez
Copy link
Member

WIP for #343 and improve support for other protocols (#333). Note I did not implement the proposed Thrift.Message as it was not required for an initial step. The main goal is to do minimal work to get Thrift.Serializable working and a step towards making the code generation for a client or server protocol independent.

Having to use %Thrift.Protocol.Binary{} to wrap binaries everywhere is awkward, perhaps we should implement binary for Thrift.Serializable or Struct.SerDe that does binary protocol too? On the other hand this should be abstracted for most usecases. I think if we wish to have Binary and Compact on equal footing we should not allow that as we want to ensure to type the payloads...

@doc """
Serialize a struct to a payload
"""
@spec serialize(thrift_struct, payload) :: payload when thrift_struct: struct, payload: var
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is the payload not iodata?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always a protocol struct, wrapping the payload. I use a variable for the type as the second arg type should always match the result type. Looks like some confusion in the code around payload and the wrapping struct due to variable naming. The structs should be renamed.

@@ -133,36 +153,6 @@ defmodule Thrift.Protocol.Binary do
{:error, {:cant_decode_message, rest}}
Copy link
Collaborator

@jparise jparise Dec 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of :cant_decode_message, would :bad_message or :decode_error be better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely should improve the error handling. I think I will do a second PR after this to introduce transport protocol that will complete the decoupling of code generation for and transports.

@jparise
Copy link
Collaborator

jparise commented Dec 2, 2018

Having to use %Thrift.Protocol.Binary{} to wrap binaries everywhere is awkward

Yes, I can see that, but I agree with your overall conclusion that this is still the best multi-protocol abstraction. I think it would only make sense to do more aggressive things if it unlocked a performance improvement, for example.

Let's proceed down the current path, and we can revisit once we have everything working.

defmodule BinaryProtocol do
@moduledoc false
unquote_splicing(binary_protocol_defs)
defprotocol SerDe do
Copy link
Collaborator

@jparise jparise Dec 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we introduce a defserde SerDe, for: name macro in Thrift.Protocol that generates this SerDe protocol for a module? We could use it here and also where we define TApplicationException.SerDe. It would be used by additional protocol implementations, too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@lATAl
Copy link

lATAl commented Jan 30, 2019

hi @fishcakez, any update for this pull?

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

Successfully merging this pull request may close these issues.

3 participants