-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow streaming of proto messages over a single network.Stream (#1081)
- Loading branch information
1 parent
de52f66
commit ecb6713
Showing
9 changed files
with
186 additions
and
237 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package starknet | ||
|
||
import ( | ||
"io" | ||
|
||
"google.golang.org/protobuf/encoding/protodelim" | ||
) | ||
|
||
var _ protodelim.Reader = (*byteReader)(nil) | ||
|
||
type byteReader struct { | ||
io.Reader | ||
} | ||
|
||
func (r *byteReader) ReadByte() (byte, error) { | ||
var b [1]byte | ||
if _, err := r.Read(b[:]); err != nil { | ||
return 0, err | ||
} | ||
return b[0], nil | ||
} |
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,27 @@ | ||
package starknet | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestByteReader(t *testing.T) { | ||
buffer := bytes.NewBuffer([]byte{1, 2, 3, 4}) | ||
bReader := byteReader{buffer} | ||
|
||
read, err := bReader.ReadByte() | ||
require.NoError(t, err) | ||
assert.Equal(t, byte(1), read) | ||
|
||
read, err = bReader.ReadByte() | ||
require.NoError(t, err) | ||
assert.Equal(t, byte(2), read) | ||
|
||
readAll, err := io.ReadAll(bReader) | ||
require.NoError(t, err) | ||
assert.Equal(t, []byte{3, 4}, readAll) | ||
} |
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
Oops, something went wrong.