-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Socket::IPAddress
constructors
#13382
Comments
I'm wondering if the type restriction on the component parameters should actually be |
@straight-shoota This would mean doing the same for every caller, sounds like avoidable PITA :) |
Yeah, that might be too annoying for using it with arbitrary numbers. |
For #13191 it'll be nice to have # port is Int32 because that's what the existing constructor uses
if v4_fields = parse_v4_fields?(address)
addr = v4(v4_fields[0], v4_fields[1], v4_fields[2], v4_fields[3], port: port.to_u16!)
elsif v6_fields = parse_v6_fields?(address)
addr = v6(v6_fields[0], v6_fields[1], v6_fields[2], v6_fields[3], v6_fields[4], v6_fields[5], v6_fields[6], v6_fields[7], port: port.to_u16!)
else
raise Error.new("Invalid IP address: #{address}")
end |
Maybe static array should be supported for splatting: Alternatively, |
It would be too easy to instantiate So I think only these overloads are necessary: struct Socket::IPAddress
def self.v4(x0 : Int, x1 : Int, x2 : Int, x3 : Int, *, port : Int) : self
end
def self.v4(fields : UInt8[4], *, port : UInt16) : self
end
# ditto for `.v6` and `.v4_mapped_v6`
end |
I don't follow the argument- why did the parameters end up as |
There's also a possible argument against representing an IPv6 address as 8 integers that are clamped to 65536. As I understand, that grouping is mainly just for convenience in text representation, but in the end the address is also just bytes. |
The idea was to have a convenience constructor that receives However I'm wondering about concrete use cases for the convenience constructor with Regarding the representation of IPv6 I suppose there are good reasons for both. The general concept is based on 16 bytes, but typical string representations use 8 numbers. |
The only ways to construct a
Socket::IPAddress
are by parsing a string or using the C representation that is not publicly documented:There should be simpler constructors to do this:
The text was updated successfully, but these errors were encountered: