The file bro.bif in the src directory contains two functions to convert count
values into ports.
function count_to_port%(c: count, t: transport_proto%): port
%{
return new PortVal(c, (TransportProto)(t->InternalInt()));
%}
function to_port%(num: count, proto: transport_proto%): port
%{
return new PortVal(num, (TransportProto)proto->AsEnum());
%}
How do they differ and which one should be used? It looks like they do
the same but have a slightly different implementation. If that's the
case, can we remove one?
Yeah, looks like one can go. We should keep the one which's naming is
more consistent with other coverters; which I believe should be
count_to_port because the first argument is a specific type (and not
"any" as other to_* function use). This is out of my memory though,
worth checking.
> function count_to_port%(c: count, t: transport_proto%): port
> function to_port%(num: count, proto: transport_proto%): port
Yeah, looks like one can go. We should keep the one which's naming is
more consistent with other coverters; which I believe should be
count_to_port because the first argument is a specific type (and not
"any" as other to_* function use). This is out of my memory though,
worth checking.
I double-checked it and it is indeed the case. In fact, the to_*
functions are all string converters and (should) have a signature of the
form