276 Members
Implementing ipfs in rust33 Servers

Load older messages

4 Jun 2021
@rklaehn:matrix.orgrklaehnTo test something like this, use assert_roundtrip.10:53:29
@vmx:mozilla.orgvmxnice! i haven't thought of, that you can implement it for your own types.10:55:39

This would be a tad more efficient:

impl Encode<DagCborCodec> for Bytes {
    fn encode<W: std::io::Write>(&self, c: DagCborCodec, w: &mut W) -> Result<()> {
        self.0.as_slice().encode(c, w)
@vmx:mozilla.orgvmxvec<u8> (or a slice) to bytes seems pretty common if i think of ipld. if that issue comes up more often it might make sense to add some annotation for the derive. sounds small scope enough that i might find some time to try that out10:57:53
@rklaehn:matrix.orgrklaehnI don't think it is possible, the way rust traits work. You want Vec<T> to serialize into an ipld sequence, but you can not "specialize" Vec<T> to use more efficient representation for some T.10:58:53
@rklaehn:matrix.orgrklaehnI guess you could do some special case in the derive macro, but I am not sure if that is a good idea. I kinda like the fact that there is little "magic".10:59:46
@vmx:mozilla.orgvmx right. i was thinking of something similar to serde_bytes. but yes, adding more complexity might not be worth it. adding a "how would i serialize a vec<u8>"-example might be better 11:05:15
@rklaehn:matrix.orgrklaehnWell, you could just add the Bytes struct from above. This does come up quite a few times, both in serde and in libipld.11:06:42
@dvc94ch:matrix.orgdvc94chadlrocha Box<[u8]> serializes to bytes, but due to lack of specialization as rklaehn mentioned Vec<u8> does not11:07:55
@dvc94ch:matrix.orgdvc94ch* adlrocha Box<[u8]> serializes to bytes, but due to lack of specialization as rklaehn mentioned Vec<u8> does not11:08:24
@rklaehn:matrix.orgrklaehnI find this a bit weird. So Box<T: DagCbor> does not work at all, because there is only a specific instance for Box<u8> but Vec<T: DagCbor> does, because there is a generic instance.11:09:30
@dvc94ch:matrix.orgdvc94chWell, it hits a set of tradeoffs that I think are not that bad11:11:51
@dvc94ch:matrix.orgdvc94chOnce we have specialization we can break everyone's code, but for now 🤷‍♂️11:12:44
@rklaehn:matrix.orgrklaehnWell, you get used to it. But in the absence of backwards compat constraints I would say: any kind of generic sequence get serialized to an ipld sequence. If you want something special, like Bytes, offer an utility struct for that, like the one above. I agree it is not the end of the world though.11:14:30
@dvc94ch:matrix.orgdvc94chI guess we can add a Bytes utility struct11:16:05
@rklaehn:matrix.orgrklaehnInteresting. But probably best to keep things simple and make it easy to write a custom encode/decode if they need something special.11:32:19
@rklaehn:matrix.orgrklaehnSo the Bytes utility struct sounds like the most straightforward solution.11:32:48
@adlrocha:matrix.orgadlrocha Thank you rklaehn , dvc94ch , vmx for your answers. This solves my questions :) 14:32:32
@adlrocha:matrix.orgadlrochaI think is fine as it is, I just couldn't understand why DagCbor derived a List instead of Bytes.14:33:06
@adlrocha:matrix.orgadlrochaQuick update: Implementing your own encodes/decoder works like a charm when you want to do things "your way". It may be useful to add a quick example to the repo. I can think of something and make a PR15:48:26
5 Jun 2021
@fusetim:matrix.orgFuseTim joined the room.14:46:18
7 Jun 2021
@david:web3.foundationDavid changed their display name from David to David - ooo (sick).11:52:39
@kezjo:matrix.orgChris-OAK Network set a profile picture.22:35:47
9 Jun 2021
@david:web3.foundationDavid changed their display name from David - ooo (sick) to David.06:20:36
10 Jun 2021
@discordian:matrix.thedisco.zoneDiscordian changed their profile picture.22:08:03
13 Jun 2021
@aditsachde:matrix.orgAdit [m.org] joined the room.21:46:24
18 Jun 2021
@chevdor:matrix.orgChevdor / Will (faster w/ @chevdor:matrix.parity.io) changed their display name from Chevdor / Will to Chevdor / Will (faster w/ @chevdor:matrix.parity.io).12:53:15
22 Jun 2021
@littlebenlittle:matrix.orglittlebenlittle changed their profile picture.14:42:25

There are no newer messages yet.

Back to Room List