Created
November 25, 2021 16:00
-
-
Save salrashid123/d532829594de623c82321d402cb0fabb to your computer and use it in GitHub Desktop.
goproto repro
This file contains hidden or 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
package main | |
/* | |
echo 0a2d48656c6c6f20756e61727920525043206d736720202066726f6d20686f73746e616d6520737261736869643132 | xxd -r -p | protoc -I`pwd`/src/echo/ --decode=echo.EchoReply `pwd`/src/echo/echo.proto | |
message: "Hello unary RPC msg from hostname srashid12" | |
*/ | |
/* | |
syntax = "proto3"; | |
package echo; | |
option go_package = "github.com/salrashid123/grpc_envoy_tap/echo"; | |
service EchoServer { | |
rpc SayHelloUnary (EchoRequest) returns (EchoReply) {} | |
rpc SayHelloClientStream(stream EchoRequest) returns (EchoReply) {} | |
rpc SayHelloServerStream(EchoRequest) returns (stream EchoReply) {} | |
rpc SayHelloBiDiStream(stream EchoRequest) returns (stream EchoReply) {} | |
} | |
message EchoRequest { | |
string name = 1; | |
} | |
message EchoReply { | |
string message = 1; | |
} | |
*/ | |
import ( | |
"bytes" | |
"encoding/base64" | |
"flag" | |
"log" | |
"google.golang.org/protobuf/proto" | |
//"github.com/golang/protobuf/proto" // deprecated | |
//"github.com/gogo/protobuf/jsonpb" | |
//"github.com/golang/protobuf/jsonpb" | |
rmsg "github.com/robinpowered/go-proto/message" | |
rstream "github.com/robinpowered/go-proto/stream" | |
"github.com/salrashid123/grpc_envoy_tap/echo" | |
) | |
var () | |
func main() { | |
flag.Parse() | |
//unary := "AAAAAC0KK1NheUhlbGxvVW5hcnkgUmVzcG9uc2U6IDU0ODcwMDU4NTkxMzc3MTQ3MTE=" | |
stream := "AAAAAB8KHVNheUhlbGxvU2VydmVyU3RyZWFtIFJlc3BvbnNlAAAAAB8KHVNheUhlbGxvU2VydmVyU3RyZWFtIFJlc3BvbnNlAAAAAB8KHVNheUhlbGxvU2VydmVyU3RyZWFtIFJlc3BvbnNlAAAAAB8KHVNheUhlbGxvU2VydmVyU3RyZWFtIFJlc3BvbnNlAAAAAB8KHVNheUhlbGxvU2VydmVyU3RyZWFtIFJlc3BvbnNl" | |
in, err := base64.URLEncoding.DecodeString(stream) | |
if err != nil { | |
log.Fatalf("could not b64 unmarshall %v", err) | |
} | |
//////////////////////////////////// | |
var f rmsg.UnmarshalFunc = func(b []byte) (proto.Message, error) { | |
var m echo.EchoReply | |
err := proto.Unmarshal(b, &m) | |
return &m, err | |
} | |
r := bytes.NewReader(in) | |
foos, err := rstream.ReadLengthPrefixedCollection(r, f) | |
if err != nil { | |
log.Fatalf("could not ReadLengthPrefixedCollection %v", err) | |
} | |
for _, ma := range foos { | |
val, ok := ma.(*echo.EchoReply) | |
if ok { | |
log.Printf("message %v", val.Message) | |
} else { | |
log.Printf("Could not convert to message %v", val.String()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment