diff --git a/examples/cmd/wsechoserver/echoserver/Makefile b/examples/cmd/wsechoserver/echoserver/Makefile index a45e997..ec0f4b0 100644 --- a/examples/cmd/wsechoserver/echoserver/Makefile +++ b/examples/cmd/wsechoserver/echoserver/Makefile @@ -1,6 +1,7 @@ all: protoc -I/usr/local/include -I. \ + -I${GOPATH}/src \ -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ - --go_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. \ + --gogo_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. \ --grpc-gateway_out=logtostderr=true:. \ echoserver.proto diff --git a/examples/cmd/wsechoserver/echoserver/echoserver.pb.go b/examples/cmd/wsechoserver/echoserver/echoserver.pb.go index 240e7de..6cc8321 100644 --- a/examples/cmd/wsechoserver/echoserver/echoserver.pb.go +++ b/examples/cmd/wsechoserver/echoserver/echoserver.pb.go @@ -1,31 +1,45 @@ -// Code generated by protoc-gen-go. +// Code generated by protoc-gen-gogo. // source: echoserver.proto // DO NOT EDIT! /* -Package echoserver is a generated protocol buffer package. + Package echoserver is a generated protocol buffer package. -It is generated from these files: - echoserver.proto + It is generated from these files: + echoserver.proto -It has these top-level messages: - EchoRequest - EchoResponse - Heartbeat - Empty + It has these top-level messages: + EchoRequest + EchoResponse + Heartbeat + Empty + Message */ package echoserver -import proto "github.com/golang/protobuf/proto" +import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" import _ "github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api" +import _ "github.com/golang/protobuf/ptypes/timestamp" +import _ "github.com/gogo/protobuf/gogoproto" + +import time "time" + +import strconv "strconv" import ( context "golang.org/x/net/context" grpc "google.golang.org/grpc" ) +import github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + +import strings "strings" +import reflect "reflect" + +import io "io" + // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf @@ -35,7 +49,7 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package type Heartbeat_Status int32 @@ -53,53 +67,377 @@ var Heartbeat_Status_value = map[string]int32{ "OK": 1, } -func (x Heartbeat_Status) String() string { - return proto.EnumName(Heartbeat_Status_name, int32(x)) -} -func (Heartbeat_Status) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{2, 0} } +func (Heartbeat_Status) EnumDescriptor() ([]byte, []int) { return fileDescriptorEchoserver, []int{2, 0} } type EchoRequest struct { - Message string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"` + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` } func (m *EchoRequest) Reset() { *m = EchoRequest{} } -func (m *EchoRequest) String() string { return proto.CompactTextString(m) } func (*EchoRequest) ProtoMessage() {} -func (*EchoRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } +func (*EchoRequest) Descriptor() ([]byte, []int) { return fileDescriptorEchoserver, []int{0} } type EchoResponse struct { - Message string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"` + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + Timestamp time.Time `protobuf:"bytes,2,opt,name=timestamp,stdtime" json:"timestamp"` } func (m *EchoResponse) Reset() { *m = EchoResponse{} } -func (m *EchoResponse) String() string { return proto.CompactTextString(m) } func (*EchoResponse) ProtoMessage() {} -func (*EchoResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } +func (*EchoResponse) Descriptor() ([]byte, []int) { return fileDescriptorEchoserver, []int{1} } + +func (m *EchoResponse) GetTimestamp() time.Time { + if m != nil { + return m.Timestamp + } + return time.Time{} +} type Heartbeat struct { - Status Heartbeat_Status `protobuf:"varint,1,opt,name=status,enum=echoserver.Heartbeat_Status" json:"status,omitempty"` + Status Heartbeat_Status `protobuf:"varint,1,opt,name=status,proto3,enum=echoserver.Heartbeat_Status" json:"status,omitempty"` } func (m *Heartbeat) Reset() { *m = Heartbeat{} } -func (m *Heartbeat) String() string { return proto.CompactTextString(m) } func (*Heartbeat) ProtoMessage() {} -func (*Heartbeat) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } +func (*Heartbeat) Descriptor() ([]byte, []int) { return fileDescriptorEchoserver, []int{2} } type Empty struct { } func (m *Empty) Reset() { *m = Empty{} } -func (m *Empty) String() string { return proto.CompactTextString(m) } func (*Empty) ProtoMessage() {} -func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } +func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptorEchoserver, []int{3} } + +type Message struct { + MessageId string `protobuf:"bytes,1,opt,name=message_id,json=messageId,proto3" json:"message_id,omitempty"` + Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"` +} + +func (m *Message) Reset() { *m = Message{} } +func (*Message) ProtoMessage() {} +func (*Message) Descriptor() ([]byte, []int) { return fileDescriptorEchoserver, []int{4} } func init() { proto.RegisterType((*EchoRequest)(nil), "echoserver.EchoRequest") proto.RegisterType((*EchoResponse)(nil), "echoserver.EchoResponse") proto.RegisterType((*Heartbeat)(nil), "echoserver.Heartbeat") proto.RegisterType((*Empty)(nil), "echoserver.Empty") + proto.RegisterType((*Message)(nil), "echoserver.Message") proto.RegisterEnum("echoserver.Heartbeat_Status", Heartbeat_Status_name, Heartbeat_Status_value) } +func (x Heartbeat_Status) String() string { + s, ok := Heartbeat_Status_name[int32(x)] + if ok { + return s + } + return strconv.Itoa(int(x)) +} +func (this *EchoRequest) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*EchoRequest) + if !ok { + that2, ok := that.(EchoRequest) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *EchoRequest") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *EchoRequest but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *EchoRequest but is not nil && this == nil") + } + if this.Message != that1.Message { + return fmt.Errorf("Message this(%v) Not Equal that(%v)", this.Message, that1.Message) + } + return nil +} +func (this *EchoRequest) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*EchoRequest) + if !ok { + that2, ok := that.(EchoRequest) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + if this.Message != that1.Message { + return false + } + return true +} +func (this *EchoResponse) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*EchoResponse) + if !ok { + that2, ok := that.(EchoResponse) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *EchoResponse") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *EchoResponse but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *EchoResponse but is not nil && this == nil") + } + if this.Message != that1.Message { + return fmt.Errorf("Message this(%v) Not Equal that(%v)", this.Message, that1.Message) + } + if !this.Timestamp.Equal(that1.Timestamp) { + return fmt.Errorf("Timestamp this(%v) Not Equal that(%v)", this.Timestamp, that1.Timestamp) + } + return nil +} +func (this *EchoResponse) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*EchoResponse) + if !ok { + that2, ok := that.(EchoResponse) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + if this.Message != that1.Message { + return false + } + if !this.Timestamp.Equal(that1.Timestamp) { + return false + } + return true +} +func (this *Heartbeat) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*Heartbeat) + if !ok { + that2, ok := that.(Heartbeat) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *Heartbeat") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *Heartbeat but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *Heartbeat but is not nil && this == nil") + } + if this.Status != that1.Status { + return fmt.Errorf("Status this(%v) Not Equal that(%v)", this.Status, that1.Status) + } + return nil +} +func (this *Heartbeat) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*Heartbeat) + if !ok { + that2, ok := that.(Heartbeat) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + if this.Status != that1.Status { + return false + } + return true +} +func (this *Empty) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*Empty) + if !ok { + that2, ok := that.(Empty) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *Empty") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *Empty but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *Empty but is not nil && this == nil") + } + return nil +} +func (this *Empty) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*Empty) + if !ok { + that2, ok := that.(Empty) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + return true +} +func (this *Message) VerboseEqual(that interface{}) error { + if that == nil { + if this == nil { + return nil + } + return fmt.Errorf("that == nil && this != nil") + } + + that1, ok := that.(*Message) + if !ok { + that2, ok := that.(Message) + if ok { + that1 = &that2 + } else { + return fmt.Errorf("that is not of type *Message") + } + } + if that1 == nil { + if this == nil { + return nil + } + return fmt.Errorf("that is type *Message but is nil && this != nil") + } else if this == nil { + return fmt.Errorf("that is type *Message but is not nil && this == nil") + } + if this.MessageId != that1.MessageId { + return fmt.Errorf("MessageId this(%v) Not Equal that(%v)", this.MessageId, that1.MessageId) + } + if this.Text != that1.Text { + return fmt.Errorf("Text this(%v) Not Equal that(%v)", this.Text, that1.Text) + } + return nil +} +func (this *Message) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*Message) + if !ok { + that2, ok := that.(Message) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + if this.MessageId != that1.MessageId { + return false + } + if this.Text != that1.Text { + return false + } + return true +} // Reference imports to suppress errors if they are not otherwise used. var _ context.Context @@ -327,30 +665,1018 @@ var _EchoService_serviceDesc = grpc.ServiceDesc{ ClientStreams: true, }, }, - Metadata: fileDescriptor0, -} - -func init() { proto.RegisterFile("echoserver.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 300 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x7c, 0x91, 0xc1, 0x4a, 0xc3, 0x40, - 0x10, 0x86, 0xdd, 0x62, 0x13, 0x3a, 0xb5, 0x12, 0x57, 0xc4, 0x50, 0x2a, 0xc8, 0x5e, 0x0c, 0x1e, - 0x92, 0x52, 0x3d, 0x79, 0xaf, 0x08, 0x85, 0x04, 0x52, 0xc4, 0xab, 0xdb, 0x30, 0x24, 0x01, 0x93, - 0x8d, 0xbb, 0xdb, 0x82, 0x57, 0x5f, 0xc1, 0x47, 0xf3, 0x15, 0x7c, 0x07, 0xaf, 0x92, 0xac, 0xc6, - 0x88, 0xa5, 0xc7, 0x99, 0xfd, 0xe6, 0x9f, 0xff, 0xdf, 0x01, 0x07, 0x93, 0x4c, 0x28, 0x94, 0x1b, - 0x94, 0x7e, 0x25, 0x85, 0x16, 0x14, 0x7e, 0x3b, 0xe3, 0x49, 0x2a, 0x44, 0xfa, 0x84, 0x01, 0xaf, - 0xf2, 0x80, 0x97, 0xa5, 0xd0, 0x5c, 0xe7, 0xa2, 0x54, 0x86, 0x64, 0x17, 0x30, 0x9c, 0x27, 0x99, - 0x88, 0xf1, 0x79, 0x8d, 0x4a, 0x53, 0x17, 0xec, 0x02, 0x95, 0xe2, 0x29, 0xba, 0xe4, 0x9c, 0x78, - 0x83, 0xf8, 0xa7, 0x64, 0x1e, 0x1c, 0x18, 0x50, 0x55, 0xa2, 0x54, 0xb8, 0x83, 0x7c, 0x84, 0xc1, - 0x1d, 0x72, 0xa9, 0x57, 0xc8, 0x35, 0xbd, 0x06, 0x4b, 0x69, 0xae, 0xd7, 0xaa, 0xa1, 0x0e, 0x67, - 0x13, 0xbf, 0x63, 0xb6, 0xc5, 0xfc, 0x65, 0xc3, 0xc4, 0xdf, 0x2c, 0x3b, 0x03, 0xcb, 0x74, 0xe8, - 0x10, 0xec, 0xfb, 0x70, 0x11, 0x46, 0x0f, 0xa1, 0xb3, 0x47, 0x2d, 0xe8, 0x45, 0x0b, 0x87, 0x30, - 0x1b, 0xfa, 0xf3, 0xa2, 0xd2, 0x2f, 0xb3, 0x4f, 0x62, 0xec, 0x2f, 0x51, 0x6e, 0xf2, 0x04, 0x69, - 0x04, 0xfb, 0x75, 0x49, 0x4f, 0xbb, 0x5b, 0x3a, 0xf9, 0xc6, 0xee, 0xff, 0x07, 0x93, 0x87, 0x39, - 0xaf, 0xef, 0x1f, 0x6f, 0x3d, 0x60, 0xfd, 0xa0, 0x26, 0x6e, 0xc8, 0xa5, 0x47, 0xa6, 0x84, 0xde, - 0xd6, 0x46, 0x24, 0xf2, 0x82, 0x1e, 0xfd, 0x99, 0xac, 0xb7, 0xef, 0x10, 0x1b, 0x35, 0x62, 0x36, - 0x35, 0x62, 0x53, 0x42, 0x23, 0x80, 0x36, 0xac, 0xda, 0xa6, 0x75, 0xb2, 0xf5, 0x5f, 0xd8, 0x71, - 0x23, 0x34, 0x62, 0xc3, 0x20, 0x6b, 0xc7, 0x6b, 0x63, 0x2b, 0xab, 0x39, 0xdf, 0xd5, 0x57, 0x00, - 0x00, 0x00, 0xff, 0xff, 0xd4, 0x6a, 0xec, 0x7b, 0xfc, 0x01, 0x00, 0x00, + Metadata: fileDescriptorEchoserver, +} + +// Client API for Messaging service + +type MessagingClient interface { + UpdateMessage(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) +} + +type messagingClient struct { + cc *grpc.ClientConn +} + +func NewMessagingClient(cc *grpc.ClientConn) MessagingClient { + return &messagingClient{cc} +} + +func (c *messagingClient) UpdateMessage(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) { + out := new(Message) + err := grpc.Invoke(ctx, "/echoserver.Messaging/UpdateMessage", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Messaging service + +type MessagingServer interface { + UpdateMessage(context.Context, *Message) (*Message, error) +} + +func RegisterMessagingServer(s *grpc.Server, srv MessagingServer) { + s.RegisterService(&_Messaging_serviceDesc, srv) +} + +func _Messaging_UpdateMessage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Message) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MessagingServer).UpdateMessage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/echoserver.Messaging/UpdateMessage", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MessagingServer).UpdateMessage(ctx, req.(*Message)) + } + return interceptor(ctx, in, info, handler) +} + +var _Messaging_serviceDesc = grpc.ServiceDesc{ + ServiceName: "echoserver.Messaging", + HandlerType: (*MessagingServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateMessage", + Handler: _Messaging_UpdateMessage_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: fileDescriptorEchoserver, +} + +func (m *EchoRequest) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *EchoRequest) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Message) > 0 { + data[i] = 0xa + i++ + i = encodeVarintEchoserver(data, i, uint64(len(m.Message))) + i += copy(data[i:], m.Message) + } + return i, nil +} + +func (m *EchoResponse) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *EchoResponse) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Message) > 0 { + data[i] = 0xa + i++ + i = encodeVarintEchoserver(data, i, uint64(len(m.Message))) + i += copy(data[i:], m.Message) + } + data[i] = 0x12 + i++ + i = encodeVarintEchoserver(data, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp))) + n1, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, data[i:]) + if err != nil { + return 0, err + } + i += n1 + return i, nil +} + +func (m *Heartbeat) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *Heartbeat) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Status != 0 { + data[i] = 0x8 + i++ + i = encodeVarintEchoserver(data, i, uint64(m.Status)) + } + return i, nil +} + +func (m *Empty) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *Empty) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + return i, nil +} + +func (m *Message) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *Message) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.MessageId) > 0 { + data[i] = 0xa + i++ + i = encodeVarintEchoserver(data, i, uint64(len(m.MessageId))) + i += copy(data[i:], m.MessageId) + } + if len(m.Text) > 0 { + data[i] = 0x12 + i++ + i = encodeVarintEchoserver(data, i, uint64(len(m.Text))) + i += copy(data[i:], m.Text) + } + return i, nil +} + +func encodeFixed64Echoserver(data []byte, offset int, v uint64) int { + data[offset] = uint8(v) + data[offset+1] = uint8(v >> 8) + data[offset+2] = uint8(v >> 16) + data[offset+3] = uint8(v >> 24) + data[offset+4] = uint8(v >> 32) + data[offset+5] = uint8(v >> 40) + data[offset+6] = uint8(v >> 48) + data[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Echoserver(data []byte, offset int, v uint32) int { + data[offset] = uint8(v) + data[offset+1] = uint8(v >> 8) + data[offset+2] = uint8(v >> 16) + data[offset+3] = uint8(v >> 24) + return offset + 4 +} +func encodeVarintEchoserver(data []byte, offset int, v uint64) int { + for v >= 1<<7 { + data[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + data[offset] = uint8(v) + return offset + 1 +} +func NewPopulatedEchoRequest(r randyEchoserver, easy bool) *EchoRequest { + this := &EchoRequest{} + this.Message = randStringEchoserver(r) + if !easy && r.Intn(10) != 0 { + } + return this +} + +func NewPopulatedEchoResponse(r randyEchoserver, easy bool) *EchoResponse { + this := &EchoResponse{} + this.Message = randStringEchoserver(r) + v1 := github_com_gogo_protobuf_types.NewPopulatedStdTime(r, easy) + this.Timestamp = *v1 + if !easy && r.Intn(10) != 0 { + } + return this +} + +func NewPopulatedHeartbeat(r randyEchoserver, easy bool) *Heartbeat { + this := &Heartbeat{} + this.Status = Heartbeat_Status([]int32{0, 1}[r.Intn(2)]) + if !easy && r.Intn(10) != 0 { + } + return this +} + +func NewPopulatedEmpty(r randyEchoserver, easy bool) *Empty { + this := &Empty{} + if !easy && r.Intn(10) != 0 { + } + return this +} + +func NewPopulatedMessage(r randyEchoserver, easy bool) *Message { + this := &Message{} + this.MessageId = randStringEchoserver(r) + this.Text = randStringEchoserver(r) + if !easy && r.Intn(10) != 0 { + } + return this +} + +type randyEchoserver interface { + Float32() float32 + Float64() float64 + Int63() int64 + Int31() int32 + Uint32() uint32 + Intn(n int) int +} + +func randUTF8RuneEchoserver(r randyEchoserver) rune { + ru := r.Intn(62) + if ru < 10 { + return rune(ru + 48) + } else if ru < 36 { + return rune(ru + 55) + } + return rune(ru + 61) +} +func randStringEchoserver(r randyEchoserver) string { + v2 := r.Intn(100) + tmps := make([]rune, v2) + for i := 0; i < v2; i++ { + tmps[i] = randUTF8RuneEchoserver(r) + } + return string(tmps) +} +func randUnrecognizedEchoserver(r randyEchoserver, maxFieldNumber int) (data []byte) { + l := r.Intn(5) + for i := 0; i < l; i++ { + wire := r.Intn(4) + if wire == 3 { + wire = 5 + } + fieldNumber := maxFieldNumber + r.Intn(100) + data = randFieldEchoserver(data, r, fieldNumber, wire) + } + return data +} +func randFieldEchoserver(data []byte, r randyEchoserver, fieldNumber int, wire int) []byte { + key := uint32(fieldNumber)<<3 | uint32(wire) + switch wire { + case 0: + data = encodeVarintPopulateEchoserver(data, uint64(key)) + v3 := r.Int63() + if r.Intn(2) == 0 { + v3 *= -1 + } + data = encodeVarintPopulateEchoserver(data, uint64(v3)) + case 1: + data = encodeVarintPopulateEchoserver(data, uint64(key)) + data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) + case 2: + data = encodeVarintPopulateEchoserver(data, uint64(key)) + ll := r.Intn(100) + data = encodeVarintPopulateEchoserver(data, uint64(ll)) + for j := 0; j < ll; j++ { + data = append(data, byte(r.Intn(256))) + } + default: + data = encodeVarintPopulateEchoserver(data, uint64(key)) + data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) + } + return data +} +func encodeVarintPopulateEchoserver(data []byte, v uint64) []byte { + for v >= 1<<7 { + data = append(data, uint8(uint64(v)&0x7f|0x80)) + v >>= 7 + } + data = append(data, uint8(v)) + return data +} +func (m *EchoRequest) Size() (n int) { + var l int + _ = l + l = len(m.Message) + if l > 0 { + n += 1 + l + sovEchoserver(uint64(l)) + } + return n +} + +func (m *EchoResponse) Size() (n int) { + var l int + _ = l + l = len(m.Message) + if l > 0 { + n += 1 + l + sovEchoserver(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp) + n += 1 + l + sovEchoserver(uint64(l)) + return n +} + +func (m *Heartbeat) Size() (n int) { + var l int + _ = l + if m.Status != 0 { + n += 1 + sovEchoserver(uint64(m.Status)) + } + return n +} + +func (m *Empty) Size() (n int) { + var l int + _ = l + return n +} + +func (m *Message) Size() (n int) { + var l int + _ = l + l = len(m.MessageId) + if l > 0 { + n += 1 + l + sovEchoserver(uint64(l)) + } + l = len(m.Text) + if l > 0 { + n += 1 + l + sovEchoserver(uint64(l)) + } + return n +} + +func sovEchoserver(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozEchoserver(x uint64) (n int) { + return sovEchoserver(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *EchoRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&EchoRequest{`, + `Message:` + fmt.Sprintf("%v", this.Message) + `,`, + `}`, + }, "") + return s +} +func (this *EchoResponse) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&EchoResponse{`, + `Message:` + fmt.Sprintf("%v", this.Message) + `,`, + `Timestamp:` + strings.Replace(strings.Replace(this.Timestamp.String(), "Timestamp", "google_protobuf1.Timestamp", 1), `&`, ``, 1) + `,`, + `}`, + }, "") + return s +} +func (this *Heartbeat) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Heartbeat{`, + `Status:` + fmt.Sprintf("%v", this.Status) + `,`, + `}`, + }, "") + return s +} +func (this *Empty) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Empty{`, + `}`, + }, "") + return s +} +func (this *Message) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Message{`, + `MessageId:` + fmt.Sprintf("%v", this.MessageId) + `,`, + `Text:` + fmt.Sprintf("%v", this.Text) + `,`, + `}`, + }, "") + return s +} +func valueToStringEchoserver(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *EchoRequest) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EchoRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EchoRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEchoserver + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Message = string(data[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEchoserver(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthEchoserver + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EchoResponse) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EchoResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EchoResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEchoserver + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Message = string(data[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEchoserver + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Timestamp, data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEchoserver(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthEchoserver + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Heartbeat) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Heartbeat: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Heartbeat: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + m.Status |= (Heartbeat_Status(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipEchoserver(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthEchoserver + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Empty) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Empty: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Empty: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipEchoserver(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthEchoserver + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Message) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Message: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Message: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MessageId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEchoserver + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MessageId = string(data[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Text", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEchoserver + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEchoserver + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Text = string(data[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEchoserver(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthEchoserver + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEchoserver(data []byte) (n int, err error) { + l := len(data) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEchoserver + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEchoserver + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if data[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEchoserver + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + iNdEx += length + if length < 0 { + return 0, ErrInvalidLengthEchoserver + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowEchoserver + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipEchoserver(data[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthEchoserver = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEchoserver = fmt.Errorf("proto: integer overflow") +) + +func init() { proto.RegisterFile("echoserver.proto", fileDescriptorEchoserver) } + +var fileDescriptorEchoserver = []byte{ + // 509 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x7c, 0x92, 0x4f, 0x8b, 0xd3, 0x40, + 0x18, 0xc6, 0x33, 0x65, 0xb7, 0x31, 0x6f, 0xad, 0xd4, 0x59, 0xc4, 0x1a, 0x76, 0xa7, 0xcb, 0x20, + 0x58, 0x16, 0x4d, 0xd6, 0xea, 0x69, 0xf1, 0x54, 0x58, 0x51, 0x16, 0x5b, 0xc8, 0xba, 0x78, 0x5c, + 0xa7, 0xed, 0x98, 0x06, 0x9a, 0x4c, 0xcc, 0x4c, 0x8b, 0x22, 0x82, 0xf8, 0x09, 0x04, 0xbf, 0x84, + 0x1f, 0x65, 0x8f, 0x82, 0x17, 0x4f, 0xba, 0x0d, 0x1e, 0x3c, 0xf6, 0xa6, 0x47, 0xc9, 0x24, 0xfd, + 0x23, 0xd6, 0xbd, 0xcd, 0xfb, 0xce, 0xef, 0x7d, 0xe6, 0x79, 0x9f, 0x04, 0x6a, 0xbc, 0x3f, 0x14, + 0x92, 0x27, 0x13, 0x9e, 0x38, 0x71, 0x22, 0x94, 0xc0, 0xb0, 0xec, 0xd8, 0xdb, 0xbe, 0x10, 0xfe, + 0x88, 0xbb, 0x2c, 0x0e, 0x5c, 0x16, 0x45, 0x42, 0x31, 0x15, 0x88, 0x48, 0xe6, 0xa4, 0xdd, 0x28, + 0x6e, 0x75, 0xd5, 0x1b, 0xbf, 0x70, 0x55, 0x10, 0x72, 0xa9, 0x58, 0x18, 0x17, 0xc0, 0x1d, 0x3f, + 0x50, 0xc3, 0x71, 0xcf, 0xe9, 0x8b, 0xd0, 0xf5, 0x85, 0x2f, 0x96, 0x64, 0x56, 0xe9, 0x42, 0x9f, + 0x72, 0x9c, 0xde, 0x82, 0xca, 0x61, 0x7f, 0x28, 0x3c, 0xfe, 0x72, 0xcc, 0xa5, 0xc2, 0x75, 0x30, + 0x43, 0x2e, 0x25, 0xf3, 0x79, 0x1d, 0xed, 0xa2, 0xa6, 0xe5, 0xcd, 0x4b, 0x3a, 0x82, 0xcb, 0x39, + 0x28, 0x63, 0x11, 0x49, 0xfe, 0x7f, 0x12, 0xb7, 0xc1, 0x5a, 0x98, 0xaa, 0x97, 0x76, 0x51, 0xb3, + 0xd2, 0xb2, 0x9d, 0xdc, 0xb6, 0x33, 0x37, 0xe3, 0x3c, 0x9d, 0x13, 0xed, 0x4b, 0x67, 0xdf, 0x1a, + 0xc6, 0x87, 0xef, 0x0d, 0xe4, 0x2d, 0xc7, 0xe8, 0x73, 0xb0, 0x1e, 0x71, 0x96, 0xa8, 0x1e, 0x67, + 0x0a, 0xdf, 0x87, 0xb2, 0x54, 0x4c, 0x8d, 0xa5, 0x7e, 0xe9, 0x4a, 0x6b, 0xdb, 0x59, 0x09, 0x70, + 0x81, 0x39, 0xc7, 0x9a, 0xf1, 0x0a, 0x96, 0xee, 0x40, 0x39, 0xef, 0xe0, 0x0a, 0x98, 0x27, 0x9d, + 0xa3, 0x4e, 0xf7, 0x59, 0xa7, 0x66, 0xe0, 0x32, 0x94, 0xba, 0x47, 0x35, 0x44, 0x4d, 0xd8, 0x3c, + 0x0c, 0x63, 0xf5, 0x9a, 0x3e, 0x00, 0xf3, 0x49, 0xe1, 0x7c, 0x07, 0xa0, 0x58, 0xe2, 0x34, 0x18, + 0x14, 0x6b, 0x59, 0x45, 0xe7, 0xf1, 0x00, 0x63, 0xd8, 0x50, 0xfc, 0x95, 0xd2, 0x3b, 0x59, 0x9e, + 0x3e, 0xb7, 0x7e, 0xa1, 0x3c, 0xc0, 0x63, 0x9e, 0x4c, 0x82, 0x3e, 0xc7, 0x5d, 0xd8, 0xc8, 0x4a, + 0x7c, 0x7d, 0xd5, 0xe3, 0x4a, 0xc2, 0x76, 0xfd, 0xdf, 0x8b, 0x3c, 0x51, 0x5a, 0x7b, 0xff, 0xe5, + 0xc7, 0xc7, 0x12, 0xd0, 0x4d, 0x37, 0x23, 0x0e, 0xd0, 0x5e, 0x13, 0xed, 0x23, 0xfc, 0x30, 0x5b, + 0x23, 0xe1, 0x2c, 0xc4, 0x57, 0xff, 0x9a, 0xcc, 0xbc, 0x5f, 0x20, 0x56, 0xd5, 0x62, 0x26, 0xce, + 0xc5, 0xf6, 0x11, 0xee, 0x02, 0x2c, 0xa2, 0x92, 0xeb, 0xb4, 0xae, 0xad, 0x4d, 0x95, 0x6e, 0x69, + 0xa1, 0x2a, 0xad, 0xb8, 0xc3, 0xc5, 0x78, 0x66, 0xac, 0x35, 0x02, 0x2b, 0xcf, 0x2d, 0x88, 0x7c, + 0x7c, 0x0a, 0xd5, 0x93, 0x78, 0xc0, 0x14, 0x9f, 0x47, 0xb9, 0xb5, 0xaa, 0x56, 0x34, 0xed, 0x75, + 0x4d, 0x7a, 0x53, 0x3f, 0x40, 0xec, 0x1b, 0xee, 0xe4, 0xae, 0x5b, 0x84, 0x2d, 0xdd, 0x37, 0xcb, + 0x0f, 0xf1, 0xf6, 0x00, 0xed, 0xb5, 0x6f, 0x7f, 0x9d, 0x12, 0xe3, 0x7c, 0x4a, 0xd0, 0x6c, 0x4a, + 0x8c, 0xdf, 0x53, 0x82, 0xde, 0xa5, 0x04, 0x7d, 0x4a, 0x09, 0x3a, 0x4b, 0x09, 0xfa, 0x9c, 0x12, + 0x74, 0x9e, 0x12, 0xf4, 0x33, 0x25, 0xc6, 0x2c, 0x25, 0xa8, 0x57, 0xd6, 0xff, 0xd9, 0xbd, 0x3f, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x1f, 0xba, 0xa0, 0xd5, 0x6a, 0x03, 0x00, 0x00, } diff --git a/examples/cmd/wsechoserver/echoserver/echoserver.pb.gw.go b/examples/cmd/wsechoserver/echoserver/echoserver.pb.gw.go index b8c89b2..814cb30 100644 --- a/examples/cmd/wsechoserver/echoserver/echoserver.pb.gw.go +++ b/examples/cmd/wsechoserver/echoserver/echoserver.pb.gw.go @@ -52,8 +52,11 @@ func request_EchoService_Echo_0(ctx context.Context, marshaler runtime.Marshaler return nil } if err := handleSend(); err != nil { - if err := stream.CloseSend(); err != nil { - grpclog.Printf("Failed to terminate client stream: %v", err) + if cerr := stream.CloseSend(); cerr != nil { + grpclog.Printf("Failed to terminate client stream: %v", cerr) + } + if err == io.EOF { + return stream, metadata, nil } return nil, metadata, err } @@ -118,8 +121,11 @@ func request_EchoService_Heartbeats_0(ctx context.Context, marshaler runtime.Mar return nil } if err := handleSend(); err != nil { - if err := stream.CloseSend(); err != nil { - grpclog.Printf("Failed to terminate client stream: %v", err) + if cerr := stream.CloseSend(); cerr != nil { + grpclog.Printf("Failed to terminate client stream: %v", cerr) + } + if err == io.EOF { + return stream, metadata, nil } return nil, metadata, err } @@ -142,6 +148,45 @@ func request_EchoService_Heartbeats_0(ctx context.Context, marshaler runtime.Mar return stream, metadata, nil } +var ( + filter_Messaging_UpdateMessage_0 = &utilities.DoubleArray{Encoding: map[string]int{"": 0, "message_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} +) + +func request_Messaging_UpdateMessage_0(ctx context.Context, marshaler runtime.Marshaler, client MessagingClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq Message + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { + return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) + } + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["message_id"] + if !ok { + return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "message_id") + } + + protoReq.MessageId, err = runtime.String(val) + + if err != nil { + return nil, metadata, err + } + + if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Messaging_UpdateMessage_0); err != nil { + return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.UpdateMessage(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + // RegisterEchoServiceHandlerFromEndpoint is same as RegisterEchoServiceHandler but // automatically dials to "endpoint" and closes the connection when "ctx" gets done. func RegisterEchoServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { @@ -274,3 +319,72 @@ var ( forward_EchoService_Heartbeats_0 = runtime.ForwardResponseStream ) + +// RegisterMessagingHandlerFromEndpoint is same as RegisterMessagingHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterMessagingHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterMessagingHandler(ctx, mux, conn) +} + +// RegisterMessagingHandler registers the http handlers for service Messaging to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterMessagingHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + client := NewMessagingClient(conn) + + mux.Handle("PUT", pattern_Messaging_UpdateMessage_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { + select { + case <-done: + case <-closed: + cancel() + } + }(ctx.Done(), cn.CloseNotify()) + } + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, req) + if err != nil { + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) + } + resp, md, err := request_Messaging_UpdateMessage_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) + return + } + + forward_Messaging_UpdateMessage_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Messaging_UpdateMessage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "messages", "message_id"}, "")) +) + +var ( + forward_Messaging_UpdateMessage_0 = runtime.ForwardResponseMessage +) diff --git a/examples/cmd/wsechoserver/echoserver/echoserver.proto b/examples/cmd/wsechoserver/echoserver/echoserver.proto index 003375a..5ca2e1f 100644 --- a/examples/cmd/wsechoserver/echoserver/echoserver.proto +++ b/examples/cmd/wsechoserver/echoserver/echoserver.proto @@ -2,6 +2,24 @@ syntax = "proto3"; package echoserver; import "google/api/annotations.proto"; +import "google/protobuf/timestamp.proto"; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +// Disables some golang/protobuf behaviour +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_enum_stringer_all) = false; +option (gogoproto.gostring_all) = false; + +// Enable gogo/protobuf features +option (gogoproto.populate_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.stringer_all) = true; +option (gogoproto.equal_all) = true; +option (gogoproto.verbose_equal_all) = true; +option (gogoproto.marshaler_all) = true; +option (gogoproto.unmarshaler_all) = true; +option (gogoproto.enum_stringer_all) = true; message EchoRequest { string message = 1; @@ -9,6 +27,10 @@ message EchoRequest { message EchoResponse { string message = 1; + google.protobuf.Timestamp timestamp = 2 [ + (gogoproto.stdtime) = true, + (gogoproto.nullable) = false + ]; } message Heartbeat { @@ -32,3 +54,17 @@ service EchoService { option (google.api.http) = {post: "/heartbeats"}; } } + + +service Messaging { + rpc UpdateMessage(Message) returns (Message) { + option (google.api.http) = { + put: "/v1/messages/{message_id}" + body: "*" + }; + } +} +message Message { + string message_id = 1; + string text = 2; +} diff --git a/examples/cmd/wsechoserver/main.go b/examples/cmd/wsechoserver/main.go index 7248653..e2369b0 100644 --- a/examples/cmd/wsechoserver/main.go +++ b/examples/cmd/wsechoserver/main.go @@ -14,6 +14,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/tmc/grpc-websocket-proxy/examples/cmd/wsechoserver/echoserver" "github.com/tmc/grpc-websocket-proxy/wsproxy" + "github.com/tmc/grpcutils" "golang.org/x/net/context" "google.golang.org/grpc" ) @@ -33,15 +34,18 @@ func run() error { return err } - mux := runtime.NewServeMux() + mux := runtime.NewServeMux(runtime.WithMarshalerOption("*", &grpcutils.JSONPb{OrigName: true})) opts := []grpc.DialOption{grpc.WithInsecure()} - err := echoserver.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *grpcAddr, opts) - if err != nil { + if err := echoserver.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *grpcAddr, opts); err != nil { + return err + } + if err := echoserver.RegisterMessagingHandlerFromEndpoint(ctx, mux, *grpcAddr, opts); err != nil { return err } go http.ListenAndServe(*debugAddr, nil) fmt.Println("listening") - http.ListenAndServe(*httpAddr, wsproxy.WebsocketProxy(mux)) + //log.Fatalnln(http.ListenAndServe(*httpAddr, mux)) + log.Fatalln(http.ListenAndServe(*httpAddr, wsproxy.WebsocketProxy(mux))) return nil } @@ -52,6 +56,8 @@ func listenGRPC(listenAddr string) error { } grpcServer := grpc.NewServer() echoserver.RegisterEchoServiceServer(grpcServer, &Server{}) + echoserver.RegisterMessagingServer(grpcServer, &Server{}) + go func() { if err := grpcServer.Serve(lis); err != nil { log.Println("serveGRPC err:", err) diff --git a/examples/cmd/wsechoserver/server.go b/examples/cmd/wsechoserver/server.go index e51a19f..e4579cb 100644 --- a/examples/cmd/wsechoserver/server.go +++ b/examples/cmd/wsechoserver/server.go @@ -5,13 +5,21 @@ import ( "fmt" "time" + "golang.org/x/net/context" + log "github.com/Sirupsen/logrus" + "github.com/davecgh/go-spew/spew" "github.com/golang/protobuf/jsonpb" "github.com/tmc/grpc-websocket-proxy/examples/cmd/wsechoserver/echoserver" ) type Server struct{} +func (s *Server) UpdateMessage(ctx context.Context, m *echoserver.Message) (*echoserver.Message, error) { + spew.Dump(m) + return &echoserver.Message{}, nil +} + func (s *Server) Stream(_ *echoserver.Empty, stream echoserver.EchoService_StreamServer) error { start := time.Now() for i := 0; i < 5; i++ { @@ -31,8 +39,16 @@ func (s *Server) Echo(srv echoserver.EchoService_EchoServer) error { if err != nil { return err } + now := time.Now() if err := srv.Send(&echoserver.EchoResponse{ - Message: req.Message + "!", + Message: req.Message + "!", + Timestamp: now, + /* + Timestamp: ×tamp.Timestamp{ + Seconds: now.Unix(), + Nanos: int32(now.Nanosecond()), + }, + */ }); err != nil { return err }