1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-19 02:16:11 -04:00
v2fly/common/net/port.go

33 lines
563 B
Go
Raw Normal View History

2015-12-02 06:47:54 -05:00
package net
import (
2015-12-03 10:57:23 -05:00
"github.com/v2ray/v2ray-core/common/serial"
2015-12-02 06:47:54 -05:00
)
2015-12-03 10:57:23 -05:00
type Port serial.Uint16Literal
2015-12-02 06:47:54 -05:00
2015-12-02 15:44:01 -05:00
func PortFromBytes(port []byte) Port {
2016-01-24 16:28:44 -05:00
return Port(serial.BytesLiteral(port).Uint16Value())
2015-12-02 06:47:54 -05:00
}
func (this Port) Value() uint16 {
return uint16(this)
}
func (this Port) Bytes() []byte {
2016-01-18 19:21:07 -05:00
return serial.Uint16Literal(this).Bytes()
2015-12-02 06:47:54 -05:00
}
func (this Port) String() string {
2015-12-03 10:57:23 -05:00
return serial.Uint16Literal(this).String()
2015-12-02 06:47:54 -05:00
}
2016-01-15 07:39:36 -05:00
type PortRange struct {
From Port
To Port
}
2016-01-17 10:20:49 -05:00
func (this PortRange) Contains(port Port) bool {
return this.From <= port && port <= this.To
}