From ee489c95b33398942bb853ac440f6fdc26cbe443 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Fri, 2 Nov 2018 15:14:34 +0100 Subject: [PATCH] remove Port.Bytes() --- common/net/port.go | 5 ----- common/protocol/address.go | 3 ++- proxy/vmess/encoding/commands.go | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/common/net/port.go b/common/net/port.go index 4da6baad1..5882da05a 100644 --- a/common/net/port.go +++ b/common/net/port.go @@ -39,11 +39,6 @@ func (p Port) Value() uint16 { return uint16(p) } -// Bytes returns the correspoding bytes of a Port, in big endian order. -func (p Port) Bytes(b []byte) []byte { - return serial.Uint16ToBytes(p.Value(), b) -} - // String returns the string presentation of a Port. func (p Port) String() string { return serial.Uint16ToString(p.Value()) diff --git a/common/protocol/address.go b/common/protocol/address.go index e1cfb3aeb..70028469d 100644 --- a/common/protocol/address.go +++ b/common/protocol/address.go @@ -7,6 +7,7 @@ import ( "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/common/task" + "v2ray.com/core/common/vio" ) type AddressOption func(*AddressParser) @@ -166,7 +167,7 @@ func (p *AddressParser) ReadAddressPort(buffer *buf.Buffer, input io.Reader) (ne } func (p *AddressParser) writePort(writer io.Writer, port net.Port) error { - return common.Error2(writer.Write(port.Bytes(nil))) + return common.Error2(vio.WriteUint16(writer, port.Value())) } func (p *AddressParser) writeAddress(writer io.Writer, address net.Address) error { diff --git a/proxy/vmess/encoding/commands.go b/proxy/vmess/encoding/commands.go index 11d93d670..f3e7ef659 100644 --- a/proxy/vmess/encoding/commands.go +++ b/proxy/vmess/encoding/commands.go @@ -9,6 +9,7 @@ import ( "v2ray.com/core/common/protocol" "v2ray.com/core/common/serial" "v2ray.com/core/common/uuid" + "v2ray.com/core/common/vio" ) var ( @@ -95,7 +96,7 @@ func (f *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.Wri common.Must2(writer.Write([]byte(hostStr))) } - common.Must2(writer.Write(cmd.Port.Bytes(nil))) + common.Must2(vio.WriteUint16(writer, cmd.Port.Value())) idBytes := cmd.ID.Bytes() common.Must2(writer.Write(idBytes))