mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-18 22:14:35 +00:00
remove go-wire and go-crypto deps
This commit is contained in:
+21
-2
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
wire "github.com/tendermint/go-wire"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,7 +18,7 @@ func WriteMessage(msg proto.Message, w io.Writer) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return wire.EncodeByteSlice(w, bz)
|
||||
return encodeByteSlice(w, bz)
|
||||
}
|
||||
|
||||
// ReadMessage reads a varint length-delimited protobuf message.
|
||||
@@ -48,6 +47,26 @@ func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) error {
|
||||
return proto.Unmarshal(buf, msg)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// NOTE: we copied wire.EncodeByteSlice from go-wire rather than keep
|
||||
// go-wire as a dep
|
||||
|
||||
func encodeByteSlice(w io.Writer, bz []byte) (err error) {
|
||||
err = encodeVarint(w, int64(len(bz)))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = w.Write(bz)
|
||||
return
|
||||
}
|
||||
|
||||
func encodeVarint(w io.Writer, i int64) (err error) {
|
||||
var buf [10]byte
|
||||
n := binary.PutVarint(buf[:], i)
|
||||
_, err = w.Write(buf[0:n])
|
||||
return
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
func ToRequestEcho(message string) *Request {
|
||||
|
||||
@@ -72,3 +72,31 @@ func TestWriteReadMessage(t *testing.T) {
|
||||
assert.Equal(t, c, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteReadMessage2(t *testing.T) {
|
||||
phrase := "hello-world"
|
||||
cases := []proto.Message{
|
||||
&ResponseCheckTx{
|
||||
Data: []byte(phrase),
|
||||
Log: phrase,
|
||||
GasWanted: 10,
|
||||
Tags: []cmn.KVPair{
|
||||
cmn.KVPair{[]byte("abc"), []byte("def")},
|
||||
},
|
||||
// Fee: cmn.KI64Pair{
|
||||
},
|
||||
// TODO: add the rest
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
buf := new(bytes.Buffer)
|
||||
err := WriteMessage(c, buf)
|
||||
assert.Nil(t, err)
|
||||
|
||||
msg := new(ResponseCheckTx)
|
||||
err = ReadMessage(buf, msg)
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Equal(t, c, msg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user