psanford / wormhole-william

End-to-end encrypted file transfer. A magic wormhole CLI and API in Go (golang).
MIT License
1.07k stars 54 forks source link

wormhole: Collect messages without using reflect package #95

Closed Jacalz closed 1 year ago

Jacalz commented 1 year ago

This implements the message collection in the waitFor method without using the reflect package. We can use a type switch and copy over the field values directly and also make sure that non-pointer values or unsupported collector types return an error.

This implementation uses a bit less "magic" and is more understandable in my opinion.

Supersedes #94

Jacalz commented 1 year ago

Test failure does not seem to be a fault of this PR. Tests are passing locally for me.

Jacalz commented 1 year ago

I rewrote the code to only use one type cast and make everything more readable over all.

psanford commented 1 year ago

Refect isn't magic. Its a fairly normal pattern in the stdlib (e.g. encoding/json encoding/xml). I don't consider the additional code to be better.

Jacalz commented 1 year ago

Yes it isn't magic but it also should be used very sparingly. I agree to disagree.