1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

remove Buffer.Append method

This commit is contained in:
Darien Raymond 2018-04-19 22:56:55 +02:00
parent 1ad429d1d4
commit 1425fd2ba9
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
17 changed files with 28 additions and 35 deletions

View File

@ -43,7 +43,7 @@ func TestReaderWriter(t *testing.T) {
writePayload := func(writer *Writer, payload ...byte) error {
b := buf.New()
b.Append(payload)
b.Write(payload)
return writer.WriteMultiBuffer(buf.NewMultiBufferValue(b))
}

View File

@ -36,15 +36,8 @@ func (b *Buffer) Clear() {
}
// AppendBytes appends one or more bytes to the end of the buffer.
func (b *Buffer) AppendBytes(bytes ...byte) int {
return b.Append(bytes)
}
// Append appends a byte array to the end of the buffer.
func (b *Buffer) Append(data []byte) int {
nBytes := copy(b.v[b.end:], data)
b.end += int32(nBytes)
return nBytes
func (b *Buffer) AppendBytes(bytes ...byte) (int, error) {
return b.Write(bytes)
}
// AppendSupplier appends the content of a BytesWriter to the buffer.

View File

@ -15,7 +15,7 @@ func TestBufferClear(t *testing.T) {
defer buffer.Release()
payload := "Bytes"
buffer.Append([]byte(payload))
buffer.Write([]byte(payload))
assert(buffer.Len(), Equals, int32(len(payload)))
buffer.Clear()

View File

@ -29,7 +29,7 @@ func TestAuthenticationReaderWriter(t *testing.T) {
rand.Read(rawPayload)
payload := buf.NewSize(payloadSize)
payload.Append(rawPayload)
payload.Write(rawPayload)
assert(payload.Len(), Equals, int32(payloadSize))
cache := buf.NewSize(160 * 1024)
@ -94,11 +94,11 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) {
var payload buf.MultiBuffer
pb1 := buf.New()
pb1.Append([]byte("abcd"))
pb1.Write([]byte("abcd"))
payload.Append(pb1)
pb2 := buf.New()
pb2.Append([]byte("efgh"))
pb2.Write([]byte("efgh"))
payload.Append(pb2)
assert(writer.WriteMultiBuffer(payload), IsNil)

View File

@ -29,7 +29,7 @@ func TestNormalChunkWriting(t *testing.T) {
[]byte{21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36})))
b := buf.NewSize(256)
b.Append([]byte{11, 12, 13, 14, 15, 16, 17, 18})
b.Write([]byte{11, 12, 13, 14, 15, 16, 17, 18})
err := writer.WriteMultiBuffer(buf.NewMultiBufferValue(b))
assert(err, IsNil)
assert(buffer.Bytes(), Equals, []byte{0, 8, 39, 228, 69, 96, 133, 39, 254, 26, 201, 70, 11, 12, 13, 14, 15, 16, 17, 18})

View File

@ -232,7 +232,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload []byte) (*buf.Buff
return nil, newError("failed to write address").Base(err)
}
buffer.Append(payload)
buffer.Write(payload)
if !account.Cipher.IsAEAD() && request.Option.Has(RequestOptionOneTimeAuth) {
authenticator := NewAuthenticator(HeaderKeyGenerator(account.Key, iv))

View File

@ -105,7 +105,7 @@ func TestTCPRequest(t *testing.T) {
runTest := func(request *protocol.RequestHeader, payload []byte) {
data := buf.New()
defer data.Release()
data.Append(payload)
data.Write(payload)
cache := buf.New()
defer cache.Release()

View File

@ -255,7 +255,7 @@ func writeSocks4Response(writer io.Writer, errCode byte, address net.Address, po
buffer.AppendBytes(0x00, errCode)
common.Must(buffer.AppendSupplier(serial.WriteUint16(port.Value())))
buffer.Append(address.IP())
buffer.Write(address.IP())
_, err := writer.Write(buffer.Bytes())
return err
}
@ -292,7 +292,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, data []byte) (*buf.Buffer,
b.Release()
return nil, err
}
b.Append(data)
b.Write(data)
return b, nil
}
@ -358,9 +358,9 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i
account := rawAccount.(*Account)
b.AppendBytes(0x01, byte(len(account.Username)))
b.Append([]byte(account.Username))
b.Write([]byte(account.Username))
b.AppendBytes(byte(len(account.Password)))
b.Append([]byte(account.Password))
b.Write([]byte(account.Password))
}
if _, err := writer.Write(b.Bytes()); err != nil {

View File

@ -24,7 +24,7 @@ func TestUDPEncoding(t *testing.T) {
content := []byte{'a'}
payload := buf.New()
payload.Append(content)
payload.Write(content)
assert(writer.WriteMultiBuffer(buf.NewMultiBufferValue(payload)), IsNil)
reader := NewUDPReader(b)

View File

@ -70,8 +70,8 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
defer buffer.Release()
buffer.AppendBytes(Version)
buffer.Append(c.requestBodyIV[:])
buffer.Append(c.requestBodyKey[:])
buffer.Write(c.requestBodyIV[:])
buffer.Write(c.requestBodyKey[:])
buffer.AppendBytes(c.responseHeader, byte(header.Option))
padingLen := dice.Roll(16)

View File

@ -42,7 +42,7 @@ func TestRequestSerialization(t *testing.T) {
common.Must(client.EncodeRequestHeader(expectedRequest, buffer))
buffer2 := buf.New()
buffer2.Append(buffer.Bytes())
buffer2.Write(buffer.Bytes())
sessionHistory := NewSessionHistory()
defer common.Close(sessionHistory)
@ -95,7 +95,7 @@ func TestInvalidRequest(t *testing.T) {
common.Must(client.EncodeRequestHeader(expectedRequest, buffer))
buffer2 := buf.New()
buffer2.Append(buffer.Bytes())
buffer2.Write(buffer.Bytes())
sessionHistory := NewSessionHistory()
defer common.Close(sessionHistory)
@ -135,7 +135,7 @@ func TestMuxRequest(t *testing.T) {
common.Must(client.EncodeRequestHeader(expectedRequest, buffer))
buffer2 := buf.New()
buffer2.Append(buffer.Bytes())
buffer2.Write(buffer.Bytes())
sessionHistory := NewSessionHistory()
defer common.Close(sessionHistory)

View File

@ -20,7 +20,7 @@ func TestSRTPWrite(t *testing.T) {
payload := buf.New()
payload.AppendSupplier(srtp.Write)
payload.Append(content)
payload.Write(content)
assert(payload.Len(), Equals, int32(len(content))+srtp.Size())
}

View File

@ -20,7 +20,7 @@ func TestUTPWrite(t *testing.T) {
payload := buf.New()
payload.AppendSupplier(utp.Write)
payload.Append(content)
payload.Write(content)
assert(payload.Len(), Equals, int32(len(content))+utp.Size())
}

View File

@ -85,7 +85,7 @@ func (w *KCPPacketWriter) Write(b []byte) (int, error) {
return len(eb), nil
}))
} else {
bb.Append(b)
bb.Write(b)
}
_, err := w.Writer.Write(bb.Bytes())

View File

@ -76,7 +76,7 @@ func (s *DataSegment) parse(conv uint16, cmd Command, opt SegmentOption, buf []b
return false, nil
}
s.Data().Clear()
s.Data().Append(buf[:dataLen])
s.Data().Write(buf[:dataLen])
buf = buf[dataLen:]
return true, buf

View File

@ -24,7 +24,7 @@ func TestDataSegment(t *testing.T) {
Number: 4,
SendingNext: 5,
}
seg.Data().Append([]byte{'a', 'b', 'c', 'd'})
seg.Data().Write([]byte{'a', 'b', 'c', 'd'})
nBytes := seg.ByteSize()
bytes := make([]byte, nBytes)

View File

@ -15,7 +15,7 @@ func TestPipeReadWrite(t *testing.T) {
pReader, pWriter := New()
payload := []byte{'a', 'b', 'c', 'd'}
b := buf.New()
b.Append(payload)
b.Write(payload)
assert(pWriter.WriteMultiBuffer(buf.NewMultiBufferValue(b)), IsNil)
rb, err := pReader.ReadMultiBuffer()
@ -29,7 +29,7 @@ func TestPipeCloseError(t *testing.T) {
pReader, pWriter := New()
payload := []byte{'a', 'b', 'c', 'd'}
b := buf.New()
b.Append(payload)
b.Write(payload)
assert(pWriter.WriteMultiBuffer(buf.NewMultiBufferValue(b)), IsNil)
pWriter.CloseError()
@ -44,7 +44,7 @@ func TestPipeClose(t *testing.T) {
pReader, pWriter := New()
payload := []byte{'a', 'b', 'c', 'd'}
b := buf.New()
b.Append(payload)
b.Write(payload)
assert(pWriter.WriteMultiBuffer(buf.NewMultiBufferValue(b)), IsNil)
assert(pWriter.Close(), IsNil)