port.go 322 B

1234567891011121314151617181920212223
  1. package net
  2. import (
  3. "strconv"
  4. )
  5. type Port uint16
  6. func NewPort(port int) Port {
  7. return Port(uint16(port))
  8. }
  9. func (this Port) Value() uint16 {
  10. return uint16(this)
  11. }
  12. func (this Port) Bytes() []byte {
  13. return []byte{byte(this >> 8), byte(this)}
  14. }
  15. func (this Port) String() string {
  16. return strconv.Itoa(int(this))
  17. }