-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
256 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ type Transport interface { | |
io.ReadWriteCloser | ||
|
||
Open() error | ||
Flush() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package avroipc | ||
|
||
import ( | ||
"compress/zlib" | ||
"io" | ||
) | ||
|
||
type zlibTransport struct { | ||
r io.ReadCloser | ||
w *zlib.Writer | ||
trans Transport | ||
} | ||
|
||
func NewZlibTransport(trans Transport, level int) (Transport, error) { | ||
w, err := zlib.NewWriterLevel(trans, level) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &zlibTransport{ | ||
w: w, | ||
trans: trans, | ||
}, nil | ||
} | ||
|
||
func (t *zlibTransport) Open() error { | ||
return t.trans.Open() | ||
} | ||
|
||
func (t *zlibTransport) Close() error { | ||
if t.r != nil { | ||
err := t.r.Close() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err := t.w.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return t.trans.Close() | ||
} | ||
|
||
func (t *zlibTransport) Read(p []byte) (int, error) { | ||
// Use lazy initialization of a reader because it immediately starts reading a header | ||
// so may hang if there is no data in the underlying transport | ||
if t.r == nil { | ||
r, err := zlib.NewReader(t.trans) | ||
if err != nil { | ||
return 0, err | ||
} | ||
t.r = r | ||
} | ||
|
||
return t.r.Read(p) | ||
} | ||
|
||
func (t *zlibTransport) Write(p []byte) (int, error) { | ||
return t.w.Write(p) | ||
} | ||
|
||
func (t *zlibTransport) Flush() error { | ||
err := t.w.Flush() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return t.trans.Flush() | ||
} |
Oops, something went wrong.