1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-02 20:15:24 +00:00
v2fly/common/net/port.go

29 lines
464 B
Go
Raw Normal View History

2015-12-02 11:47:54 +00:00
package net
import (
2015-12-03 15:57:23 +00:00
"github.com/v2ray/v2ray-core/common/serial"
2015-12-02 11:47:54 +00:00
)
2015-12-03 15:57:23 +00:00
type Port serial.Uint16Literal
2015-12-02 11:47:54 +00:00
2015-12-02 20:44:01 +00:00
func PortFromBytes(port []byte) Port {
return Port(uint16(port[0])<<8 + uint16(port[1]))
2015-12-02 11:47:54 +00:00
}
func (this Port) Value() uint16 {
return uint16(this)
}
func (this Port) Bytes() []byte {
return []byte{byte(this >> 8), byte(this)}
}
func (this Port) String() string {
2015-12-03 15:57:23 +00:00
return serial.Uint16Literal(this).String()
2015-12-02 11:47:54 +00:00
}
2016-01-15 12:39:36 +00:00
type PortRange struct {
From Port
To Port
}