diff --git a/common/protocol/time.go b/common/protocol/time.go index 4fd9310f5..134a8ad59 100644 --- a/common/protocol/time.go +++ b/common/protocol/time.go @@ -10,7 +10,7 @@ import ( type Timestamp int64 func (this Timestamp) Bytes() []byte { - return serial.Int64Literal(this).Bytes() + return serial.Int64ToBytes(int64(this)) } type TimestampGenerator func() Timestamp diff --git a/common/serial/numbers.go b/common/serial/numbers.go index 62013f869..e933f55fb 100644 --- a/common/serial/numbers.go +++ b/common/serial/numbers.go @@ -12,88 +12,29 @@ func Uint16ToString(value uint16) string { return strconv.Itoa(int(value)) } +func Uint32ToBytes(value uint32) []byte { + return []byte{ + byte(value >> 24), + byte(value >> 16), + byte(value >> 8), + byte(value), + } +} + +func IntToBytes(value int) []byte { + return []byte{ + byte(value >> 24), + byte(value >> 16), + byte(value >> 8), + byte(value), + } +} + func IntToString(value int) string { return Int64ToString(int64(value)) } -func Int64ToString(value int64) string { - return strconv.FormatInt(value, 10) -} - -type Uint16 interface { - Value() uint16 -} - -type Uint16Literal uint16 - -func (this Uint16Literal) String() string { - return strconv.Itoa(int(this)) -} - -func (this Uint16Literal) Value() uint16 { - return uint16(this) -} - -func (this Uint16Literal) Bytes() []byte { - return []byte{byte(this >> 8), byte(this)} -} - -type Int interface { - Value() int -} - -type IntLiteral int - -func (this IntLiteral) String() string { - return strconv.Itoa(int(this)) -} - -func (this IntLiteral) Value() int { - return int(this) -} - -func (this IntLiteral) Bytes() []byte { - value := this.Value() - return []byte{ - byte(value >> 24), - byte(value >> 16), - byte(value >> 8), - byte(value), - } -} - -type Uint32Literal uint32 - -func (this Uint32Literal) String() string { - return strconv.FormatUint(uint64(this.Value()), 10) -} - -func (this Uint32Literal) Value() uint32 { - return uint32(this) -} - -func (this Uint32Literal) Bytes() []byte { - value := this.Value() - return []byte{ - byte(value >> 24), - byte(value >> 16), - byte(value >> 8), - byte(value), - } -} - -type Int64Literal int64 - -func (this Int64Literal) String() string { - return strconv.FormatInt(this.Value(), 10) -} - -func (this Int64Literal) Value() int64 { - return int64(this) -} - -func (this Int64Literal) Bytes() []byte { - value := this.Value() +func Int64ToBytes(value int64) []byte { return []byte{ byte(value >> 56), byte(value >> 48), @@ -105,3 +46,7 @@ func (this Int64Literal) Bytes() []byte { byte(value), } } + +func Int64ToString(value int64) string { + return strconv.FormatInt(value, 10) +} diff --git a/proxy/shadowsocks/ota.go b/proxy/shadowsocks/ota.go index 9de61c20d..30760240e 100644 --- a/proxy/shadowsocks/ota.go +++ b/proxy/shadowsocks/ota.go @@ -49,7 +49,7 @@ func ChunkKeyGenerator(iv []byte) func() []byte { return func() []byte { newKey := make([]byte, 0, len(iv)+4) newKey = append(newKey, iv...) - newKey = append(newKey, serial.IntLiteral(chunkId).Bytes()...) + newKey = append(newKey, serial.IntToBytes(chunkId)...) chunkId++ return newKey } diff --git a/proxy/vmess/outbound/receiver_json.go b/proxy/vmess/outbound/receiver_json.go index cf385235d..8017474ba 100644 --- a/proxy/vmess/outbound/receiver_json.go +++ b/proxy/vmess/outbound/receiver_json.go @@ -32,7 +32,7 @@ func (this *Receiver) UnmarshalJSON(data []byte) error { return internal.ErrorBadConfiguration } if rawConfig.Address.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) { - rawConfig.Address.Address = v2net.IPAddress(serial.Uint32Literal(2891346854).Bytes()) + rawConfig.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(2891346854)) } this.Destination = v2net.TCPDestination(rawConfig.Address.Address, rawConfig.Port) return nil