From e2bfdec012db7baa4adc55448d77567c44080224 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sun, 14 Oct 2018 08:05:23 +0200 Subject: [PATCH] rename ReadFrom to Unmarshal --- app/proxyman/mux/frame.go | 10 +++++----- app/proxyman/mux/mux.go | 4 ++-- app/proxyman/mux/mux_test.go | 18 +++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/proxyman/mux/frame.go b/app/proxyman/mux/frame.go index 13c5ec9e..b2caa144 100644 --- a/app/proxyman/mux/frame.go +++ b/app/proxyman/mux/frame.go @@ -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()) } diff --git a/app/proxyman/mux/mux.go b/app/proxyman/mux/mux.go index 73e4b2f5..a8784758 100644 --- a/app/proxyman/mux/mux.go +++ b/app/proxyman/mux/mux.go @@ -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) } diff --git a/app/proxyman/mux/mux_test.go b/app/proxyman/mux/mux_test.go index f70e74ca..1c96298c 100644 --- a/app/proxyman/mux/mux_test.go +++ b/app/proxyman/mux/mux_test.go @@ -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) }