Closed JulianSchmid closed 1 year ago
Hello! I noticed that a major refactor is in the works as per PR #47. Would it be fine for me to work on this now or is is it advisable to wait so that this PR(which comes with a lot of changes) lands.
Hi @0xcrust
I would wait until I at least have merged it to master. I will try to at least merge a partial state this weekend.
Greets Julian
Hi @0xcrust ,
I merged https://github.com/JulianSchmid/etherparse/pull/47 to master. There will be additional changes, but no where near to the same extend.
Greets Julian
Great! I'd like to go ahead with this then if that's fine
That would be great 😀
Task
Rewrite
EtherType
&IpNumber
to be single value structs. E.g.:Also add implementations of the
From
&Into
traits for simply converting fromu8
/u16
into the struct type and from the struct type intou8
/u16
. Also manually implement theDebug
andDisplay
to also display the human readable name if available (e.g.IPv4(0x0800)
forEtherType(0x0800)
).Why
Both
EtherType
andIpNumber
are currently implemented as simple enums. E.g.:Originally the plan was to use the enums in the headers. But this approach was discarded in early versions of the library as it would limit the values to only the ones present in the enums. Additionally adding an
Unknown(u8)
value to the enums would disabled the ability to simply cast the values to their underlying type and added unneeded computation when converting from and into the enum type. So the headers were switched back to the underlying typesu8
&u16
to support all valid IP & Ethernet headers.But some time ago I noticed that that the
pcap
crate had implemented theLinktype
as struct with a simple value ( https://docs.rs/pcap/1.0.0/pcap/struct.Linktype.html ). To me this seems the more sensible approach forEtherType
&IpNumber
as well, as it comes with the following advantages:u8
/u16
) from and to the struct type.Debug
orDisplay
.