-
Notifications
You must be signed in to change notification settings - Fork 115
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
Consider renaming Codec::{In, Out} #135
Comments
Encode and Decode? |
I think this is symptomatic of a subtle issue with the Codec trait. As it stands, a Codec is a trait which knows how to serialize or deserialize frames, but the types of those frames may be different in either direction. Although it is reasonable when considering that a Codec will often be implemented for a request/response protocol where different types are flowing in different directions, it conflicts with the plain meaning of the word "codec". I think when most people think of a "codec", they think of something that encodes and decodes data of the same type. For example, and audio codec deserializes bytes to audio, and serializes audio to bytes. It wouldn't be natural to call something a codec that deserializes bytes to audio, and serializes video to bytes. I think that my vote for the In and Out types are "Incoming" for the type that decode() returns, and "Outgoing" as the type that encode() takes. The mental model is that the codec sits between you and the internet/transport/whatever, and it takes Outgoing objects to encode, and gives you Incoming objects that have been decoded from the wire. Tangent, but why is Codec a single trait, instead of an Encoder and a Decoder? I'm trying to figure this out, like perhaps there's a situation where the deserializer and serializer need to share state, but I can't think of a case where that would be needed. |
If |
@casey we originally had the trait split, but it ended up coming at a hit to the common case of ergonomics, so we ended up unifying it into one, but retaining the two associated types to support similar use cases. Note that |
|
Transmit / Receive? |
Done in https://github.com/alexcrichton/tokio-io, the migration of this crate will be tracked by #61 |
Moved over from tokio-rs/tokio-proto#64, but the terminology of "in" and "out" can be confusing from time to time. Can we figure out names which are unambiguous?
The text was updated successfully, but these errors were encountered: