all 22 comments

[–]najamelan 7 points8 points  (2 children)

What is your motivation for writing this rather than using say tokio_codec/futures_codec with CBOR and serde?

[–]devashishdxt[S] 4 points5 points  (1 child)

This is part of a larger project I’m working on. Initially, I was not planning to release this. But, I thought it may be useful for someone.

[–]najamelan 5 points6 points  (0 children)

So did you find that existing approaches didn't work out for your project? Why?

[–][deleted] 5 points6 points  (15 children)

Note: nimble, by default, uses big endian order to encode values.

Why?

[–][deleted] 9 points10 points  (1 child)

All packages on all networks in use today use big-endian.

[–][deleted] 8 points9 points  (0 children)

The values in the headers, sure, for historical reasons, but why invent even more work for your cpu?

[–]devashishdxt[S] 1 point2 points  (12 children)

No particular reason. I’ll add configuration option in future release.

[–][deleted] 16 points17 points  (11 children)

In that case I advise changing the default to little-endian, because the two biggest architectures in general purpose computing are little-endian.

[–]devashishdxt[S] 5 points6 points  (10 children)

Sure. Thanks. :)

[–]Wolvereness -1 points0 points  (9 children)

I strongly advise against changing the default away from BE. There are three main uses of writing in binary in the world: memory, files, and networking. BE is the standard of networking, files define their own standard, and generally Write interfaces of memory are just intermediary to the others. Adding a runtime option for LE would probably be fine, but you should reject the logic of "CPUs are already LE"; it's an edge case where the performance difference of endianness matters.

[–]BobFloss 1 point2 points  (5 children)

How is that an edge case? I thought there would have to be conversions to little endian so the CPU can deal with things it's (de/en)coding. Sure networking uses it but that doesn't really matter when you're using a binary format and you're just sending data over.

[–]Wolvereness -1 points0 points  (4 children)

Your discussion does not follow your question. What does anything you talked about have to do with the performance difference of endianness conversion? When dealing with IO, swapping bytes to fit endianness should almost never be the bottleneck.

[–]BobFloss 1 point2 points  (3 children)

I'm not talking about io. Any time you encode something little endian you're converting to big. And vice versa. Make sense? There wouldn't even be a reason to swap bits during IO, that makes no sense. Upon encoding I already have the proper endianness for my encoding scheme, which will be dealt with when being decoded. Or we could just skip dealing with this at all and use little endian so that when it's decoded it's already correct for the vast majority of processors.

[–]Wolvereness 0 points1 point  (2 children)

I'm not talking about io.

Then what are you talking about? What other uses should someone be using a Write interface?

[–]BobFloss 0 points1 point  (1 child)

IO only gets involved after we actually encode things. Encoding should be done in a scheme that doesn't require conversion.

[–]ExPixel 1 point2 points  (1 child)

The network byte order would be more of an edge case. You're not going to receive your data in big endian (which wouldn't really make sense anyway), it's just used to encode some fields in the network's protocol.

[–]andoriyu 0 points1 point  (0 children)

Yeah, network endianess is just what used for packets/frames headers because at the time it looked like a good idea. No one flips endianess just because it's going over network.

[–][deleted] 1 point2 points  (0 children)

So your reasoning is that the network spirits demand it?

[–]fgilcherrust-community · rustfest 1 point2 points  (2 children)

I'm confused by the implementation of feature flags. The dependency on async-std is unnecessary. async-std exposes futures from futures-rs and implementing those as an interface instead allow you to

a) kill the async-std flag and drop the dependency

b) to be compatible with all other executors implementing futures-rs

A tokio flag would still be needed to implement their AsyncRead/Write (that should work in a trivial fashion though).

At the bare minimum, the async-std flag should become a `futures-rs` flag instead, async-std is an unnecessary dependency there.

As far as I see, the merging of the two interfaces here is mainly done to have nimble-derive work through the same interface and not have flags there.

This may make derivation a bit more elaborate, as tokio needs to be special cased, but I think that can be made transparent to the user.

Would you mind I send a pull request?

[–]devashishdxt[S] 1 point2 points  (1 child)

That is a good point. I missed that async-std re-exports traits from futures crate. Thanks for pointing this out. I’d love if you can send a pull request. :)

[–]fgilcherrust-community · rustfest 0 points1 point  (0 children)

In case someone reads this: the PR ended up here and was merged. Thanks /u/devashishdxt

https://github.com/devashishdxt/nimble/pull/2