Closed szihai closed 5 years ago
Once rsocket-go has the interaction basic interaction models working we can create rsocket-rpc-go pretty easily like .NET, Java, JavaScript, etc
Cool. But let's keep this issue open as a place holder for the task.
Why would you add protobuf to this code? Users should be able to set their MIME for metadata and data and use whatever serialization their applications need. As a transport, rsocket should be agnostic to serialization.
Implement payload.Payload
interface. Here're some examples:
package example
import (
"encoding/hex"
"github.com/golang/protobuf/proto"
"github.com/rsocket/rsocket-go/payload"
)
type ProtobufPayload struct {
d proto.Message
m []byte
}
func (p *ProtobufPayload) Metadata() (metadata []byte, ok bool) {
if len(p.m) < 1 {
return
}
return p.m, true
}
func (p *ProtobufPayload) MetadataUTF8() (metadata string, ok bool) {
if len(p.m) < 1 {
return
}
return string(p.m), true
}
func (p *ProtobufPayload) Data() []byte {
bs, err := proto.Marshal(p.d)
if err != nil {
panic(err)
}
return bs
}
func (p *ProtobufPayload) DataUTF8() string {
bs, err := proto.Marshal(p.d)
if err != nil {
panic(err)
}
return hex.EncodeToString(bs)
}
func (p *ProtobufPayload) Release() {
// ignore
}
func NewProtobufPayload(data proto.Message, metadata []byte) payload.Payload {
return &ProtobufPayload{
d: data,
m: metadata,
}
}
Protobuf is an important encoding mechanism. It is especially important for golang since GRpc is widely used by go programmers.