titzer / virgil

A fast and lightweight native programming language
1.13k stars 40 forks source link

[net] Minor refactorings to make Net.v3 more Virgilic #252

Closed titzer closed 2 weeks ago

titzer commented 2 weeks ago

Creating a PR to get input from @k-sareen on some minor refactorings to make the net code more Virgilic.

titzer commented 2 weeks ago

This code was written before layouts were merged

Indeed, I thought of going ahead and doing this, but alas, it uses big-endian integers, which are on the TODO list for layouts. I was not sure how client code uses serialized addresses, but another possible design is to have methods that write the serialized address out, and client code supplies an allocated for Range<byte>, which could be a method like the acquire method of a DataWriter.

k-sareen commented 2 weeks ago

Indeed, I thought of going ahead and doing this, but alas, it uses big-endian integers, which are on the TODO list for layouts.

Ah yeah the network-byte order thing is annoying. Tbh I am not sure why it was designed in such a way, but here we are.

I was not sure how client code uses serialized addresses, but another possible design is to have methods that write the serialized address out, and client code supplies an allocated for Range<byte>, which could be a method like the acquire method of a DataWriter.

I'm not sure I follow? Are you asking how code that uses this library is supposed to create new addresses? You would just need to define an InetAddress (so for example, def inetAddr = InetAddress.Ipv4(10,0,10,6);) and then can use inetAddr anywhere you want to create a socket.