Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
implement io.ByteReader in socket transport (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ortuman authored Dec 13, 2021
1 parent f7f39f7 commit 17a2237
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/transport/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ func (s *socketTransport) Read(p []byte) (n int, err error) {
return s.rd.Read(p)
}

func (s *socketTransport) ReadByte() (byte, error) {
var p [1]byte
n, err := s.rd.Read(p[:])
switch {
case n == 1 && err == nil:
return p[0], nil
case err != nil:
return 0, err
default:
return 0, nil
}
}

func (s *socketTransport) Write(p []byte) (n int, err error) {
if s.bw == nil {
s.grabBuffWriter()
Expand Down
1 change: 1 addition & 0 deletions pkg/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
// Transport represents a stream transport mechanism.
type Transport interface {
io.ReadWriteCloser
io.ByteReader

// Type returns transport type value.
Type() Type
Expand Down

0 comments on commit 17a2237

Please sign in to comment.