oh this is fun i’m rewriting some code from C to Rust, which converts a DNS name from trie key format back to wire format, to help with fuzzing and property testing my original version does it in three passes, 90 lines of code github.com/fanf2/nsd/blob/fa…
1
4
(the original C also has some extra complexity because it’s doing a base64-style decode too, which I don’t [yet] need in the rust version)
1
the reason the C needs three passes is so that it can reverse the order of the labels in the name, from lexicographical order (big endian) in the trie key, into DNS wire format (little endian)
1
after some effort working out how to do it nicely in Rust, i have some handy support for parsing DNS names from wire format in various ways so in my rewrite from C there only needs to be one pass, not three
1
how can i reduce it from three passes to one? I can use a temporary buffer and write out the labels in the order I see them (the reverse of what I want them to end up) BUT here’s the fun trick i can stick DNS name compression pointers in between them
1
so after my one-pass trie-name to DNS-name conversion, I tell my generic DNS wire format parser to do its thing, and it will decompress and reverse the labels for me so in effect I have already written two of the passes, and I can invoke them with one line of code
3
1
Replying to @fanf
seems like you have been enjoying your forays into rust. I'm glad to hear it.

Jun 4, 2021 Β· 10:04 PM UTC

1
Replying to @dsilverstone
yeah i feel i'm getting the hang of it i had a lengthy discussion with the borrow checker which was quite instructive wrt how to design data structures that work or don't (hard to unpick because my thinking was unclear in several ways when the code didn't work!)