mirror of https://github.com/v2ray/v2ray-core
rename ReadFrom to Unmarshal
parent
351316490d
commit
e2bfdec012
|
@ -88,8 +88,8 @@ func (f FrameMetadata) WriteTo(b *buf.Buffer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ReadFrom reads FrameMetadata from the given reader.
|
||||
func (f *FrameMetadata) ReadFrom(reader io.Reader) error {
|
||||
// Unmarshal reads FrameMetadata from the given reader.
|
||||
func (f *FrameMetadata) Unmarshal(reader io.Reader) error {
|
||||
metaLen, err := serial.ReadUint16(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -104,12 +104,12 @@ func (f *FrameMetadata) ReadFrom(reader io.Reader) error {
|
|||
if err := b.Reset(buf.ReadFullFrom(reader, int32(metaLen))); err != nil {
|
||||
return err
|
||||
}
|
||||
return f.ReadFromBuffer(b)
|
||||
return f.UnmarshalFromBuffer(b)
|
||||
}
|
||||
|
||||
// ReadFromBuffer reads a FrameMetadata from the given buffer.
|
||||
// UnmarshalFromBuffer reads a FrameMetadata from the given buffer.
|
||||
// Visible for testing only.
|
||||
func (f *FrameMetadata) ReadFromBuffer(b *buf.Buffer) error {
|
||||
func (f *FrameMetadata) UnmarshalFromBuffer(b *buf.Buffer) error {
|
||||
if b.Len() < 4 {
|
||||
return newError("insufficient buffer: ", b.Len())
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ func (m *Client) fetchOutput() {
|
|||
|
||||
var meta FrameMetadata
|
||||
for {
|
||||
err := meta.ReadFrom(reader)
|
||||
err := meta.Unmarshal(reader)
|
||||
if err != nil {
|
||||
if errors.Cause(err) != io.EOF {
|
||||
newError("failed to read metadata").Base(err).WriteToLog()
|
||||
|
@ -446,7 +446,7 @@ func (w *ServerWorker) handleStatusEnd(meta *FrameMetadata, reader *buf.Buffered
|
|||
|
||||
func (w *ServerWorker) handleFrame(ctx context.Context, reader *buf.BufferedReader) error {
|
||||
var meta FrameMetadata
|
||||
err := meta.ReadFrom(reader)
|
||||
err := meta.Unmarshal(reader)
|
||||
if err != nil {
|
||||
return newError("failed to read metadata").Base(err)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func TestReaderWriter(t *testing.T) {
|
|||
bytesReader := &buf.BufferedReader{Reader: pReader}
|
||||
|
||||
var meta FrameMetadata
|
||||
err := meta.ReadFrom(bytesReader)
|
||||
err := meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNil)
|
||||
assert(meta.SessionID, Equals, uint16(1))
|
||||
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
|
||||
|
@ -74,14 +74,14 @@ func TestReaderWriter(t *testing.T) {
|
|||
assert(len(data), Equals, 1)
|
||||
assert(data[0].String(), Equals, "abcd")
|
||||
|
||||
err = meta.ReadFrom(bytesReader)
|
||||
err = meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNil)
|
||||
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
|
||||
assert(meta.SessionID, Equals, uint16(2))
|
||||
assert(byte(meta.Option), Equals, byte(0))
|
||||
assert(meta.Target, Equals, dest2)
|
||||
|
||||
err = meta.ReadFrom(bytesReader)
|
||||
err = meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNil)
|
||||
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusKeep))
|
||||
assert(meta.SessionID, Equals, uint16(1))
|
||||
|
@ -92,7 +92,7 @@ func TestReaderWriter(t *testing.T) {
|
|||
assert(len(data), Equals, 1)
|
||||
assert(data[0].String(), Equals, "efgh")
|
||||
|
||||
err = meta.ReadFrom(bytesReader)
|
||||
err = meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNil)
|
||||
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
|
||||
assert(meta.SessionID, Equals, uint16(3))
|
||||
|
@ -104,19 +104,19 @@ func TestReaderWriter(t *testing.T) {
|
|||
assert(len(data), Equals, 1)
|
||||
assert(data[0].String(), Equals, "x")
|
||||
|
||||
err = meta.ReadFrom(bytesReader)
|
||||
err = meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNil)
|
||||
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
|
||||
assert(meta.SessionID, Equals, uint16(1))
|
||||
assert(byte(meta.Option), Equals, byte(0))
|
||||
|
||||
err = meta.ReadFrom(bytesReader)
|
||||
err = meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNil)
|
||||
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
|
||||
assert(meta.SessionID, Equals, uint16(3))
|
||||
assert(byte(meta.Option), Equals, byte(0))
|
||||
|
||||
err = meta.ReadFrom(bytesReader)
|
||||
err = meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNil)
|
||||
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusKeep))
|
||||
assert(meta.SessionID, Equals, uint16(2))
|
||||
|
@ -127,7 +127,7 @@ func TestReaderWriter(t *testing.T) {
|
|||
assert(len(data), Equals, 1)
|
||||
assert(data[0].String(), Equals, "y")
|
||||
|
||||
err = meta.ReadFrom(bytesReader)
|
||||
err = meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNil)
|
||||
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
|
||||
assert(meta.SessionID, Equals, uint16(2))
|
||||
|
@ -135,6 +135,6 @@ func TestReaderWriter(t *testing.T) {
|
|||
|
||||
pWriter.Close()
|
||||
|
||||
err = meta.ReadFrom(bytesReader)
|
||||
err = meta.Unmarshal(bytesReader)
|
||||
assert(err, IsNotNil)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue