status-go/vendor/github.com/libp2p/go-msgio/pbio/interfaces.go

41 lines
634 B
Go
Raw Normal View History

// Package pbio reads and writes varint-prefix protobufs, using Google's Protobuf package.
package pbio
import (
"io"
"google.golang.org/protobuf/proto"
)
type Writer interface {
WriteMsg(proto.Message) error
}
type WriteCloser interface {
Writer
io.Closer
}
type Reader interface {
ReadMsg(msg proto.Message) error
}
type ReadCloser interface {
Reader
io.Closer
}
func getSize(v interface{}) (int, bool) {
if sz, ok := v.(interface {
Size() (n int)
}); ok {
return sz.Size(), true
} else if sz, ok := v.(interface {
ProtoSize() (n int)
}); ok {
return sz.ProtoSize(), true
} else {
return 0, false
}
}