-
Notifications
You must be signed in to change notification settings - Fork 44
(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
base: master
Are you sure you want to change the base?
Conversation
@doc """ | ||
Serialize a struct to a payload | ||
""" | ||
@spec serialize(thrift_struct, payload) :: payload when thrift_struct: struct, payload: var |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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}} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
hi @fishcakez, any update for this pull? |
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 getThrift.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
forThrift.Serializable
orStruct.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...