-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
Currently (pending #8287), libextra will have the following encodings
- json
- ebml
- base64
- hex
And in theory we should add these in the future:
- xml
- base32
- ASN.1
(or at least those are the ones I could think of off the top of my head). Right now they're all placed directly inside the libextra folder, but they would probably benefit from a better organization scheme.
Currently all of the "encodings" can generally fall into two categories. One is "bytes to strings and back" and the other is a "generic serialization format".
Right now I believe that the "generic serialization format" is captured nicely via the serialize::{Encoder, Decoder} traits, and it unifies json/ebml. @omasanori has brought up concerns about the naming scheme, and my proposal below might alleviate these concerns.
Otherwise, the "bytes to strings and back" type of encoding isn't very well unified at this point. There should be a trait (in possibly a new extra::encoding module) which unifies base64/base32/hex and whatever else we come across. In my opinion, the trait should look like:
trait Text {
fn encode(&[u8]) -> ~str;
fn decode(&str) -> ~[u8];
}This makes it clear what the "encode" procedure is and what the "decode" procedure is. Additionally, it's explicitly clear that bytes live on one side, and strings live on the other, there's no intermingling between the two of them.
Finally, I think we should move everything around into:
extra::encoding::base64extra::encoding::base32extra::encoding::hexextra::encoding::jsonextra::encoding::ebml
And then encoding/mod.rs would define the traits
Text(is the name too short? if you reference it byencoding::TextI think it's clear but that's not always guaranteed)Serializer(serialize::Encodertoday)Deserializer(serialize::Decodertoday)
What do others think about this? If this looks good, I'd be more than happy to reorganize everything!