1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-04-25 23:19:09 -04:00

refactor io package

This commit is contained in:
Darien Raymond
2016-12-09 13:17:34 +01:00
parent 055023fdd5
commit 1948d0738f
36 changed files with 390 additions and 414 deletions

View File

@@ -1,12 +1,8 @@
package serial
import (
"hash"
import "hash"
"v2ray.com/core/common/buf"
)
func WriteHash(h hash.Hash) buf.Supplier {
func WriteHash(h hash.Hash) func([]byte) (int, error) {
return func(b []byte) (int, error) {
h.Sum(b[:0])
return h.Size(), nil

View File

@@ -1,10 +1,6 @@
package serial
import (
"strconv"
"v2ray.com/core/common/buf"
)
import "strconv"
func Uint16ToBytes(value uint16, b []byte) []byte {
return append(b, byte(value>>8), byte(value))
@@ -14,7 +10,7 @@ func Uint16ToString(value uint16) string {
return strconv.Itoa(int(value))
}
func WriteUint16(value uint16) buf.Supplier {
func WriteUint16(value uint16) func([]byte) (int, error) {
return func(b []byte) (int, error) {
b = Uint16ToBytes(value, b[:0])
return 2, nil
@@ -29,7 +25,7 @@ func Uint32ToString(value uint32) string {
return strconv.FormatUint(uint64(value), 10)
}
func WriteUint32(value uint32) buf.Supplier {
func WriteUint32(value uint32) func([]byte) (int, error) {
return func(b []byte) (int, error) {
b = Uint32ToBytes(value, b[:0])
return 4, nil

View File

@@ -3,8 +3,6 @@ package serial
import (
"fmt"
"strings"
"v2ray.com/core/common/buf"
)
func ToString(v interface{}) string {
@@ -36,7 +34,7 @@ func Concat(v ...interface{}) string {
return strings.Join(values, "")
}
func WriteString(s string) buf.Supplier {
func WriteString(s string) func([]byte) (int, error) {
return func(b []byte) (int, error) {
return copy(b, []byte(s)), nil
}