Permalink
Browse files

Update

  • Loading branch information...
peter-edge committed Dec 3, 2017
1 parent c5da4db commit 4e9a6dfc7fa5e3cba55588dd4756c317adf8d8fa

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -4,7 +4,7 @@ import (
"fmt"
"io"

"go.pedge.io/pb/go/google/protobuf"
"github.com/golang/protobuf/ptypes/wrappers"
"go.pedge.io/proto/stream"
)

@@ -19,7 +19,7 @@ func send(reader io.Reader, streamingBytesServer protostream.StreamingBytesServe
p = p[:n]
}
if err := streamingBytesServer.Send(
&google_protobuf.BytesValue{
&wrappers.BytesValue{
Value: p,
},
); err != nil {
@@ -8,9 +8,9 @@ import (
"google.golang.org/grpc"

"go.pedge.io/lion/proto"
"go.pedge.io/pb/go/google/protobuf"

"github.com/golang/protobuf/proto"
durationpb "github.com/golang/protobuf/ptypes/duration"
)

var (
@@ -124,7 +124,7 @@ func event(serviceName string, methodName string, request proto.Message, respons
call := &Call{
Service: serviceName,
Method: methodName,
Duration: google_protobuf.DurationToProto(duration),
Duration: durationToProto(duration),
}
if request != nil {
call.Request = request.String()
@@ -144,3 +144,10 @@ func getMethodName(depth int) string {
split := strings.Split(runtime.FuncForPC(pc[0]).Name(), ".")
return split[len(split)-1]
}

func durationToProto(d time.Duration) *durationpb.Duration {
return &durationpb.Duration{
Seconds: int64(d) / int64(time.Second),
Nanos: int32(int64(d) % int64(time.Second)),
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -10,14 +10,14 @@ import (

"go.pedge.io/env"
"go.pedge.io/lion/proto"
"go.pedge.io/pb/go/google/protobuf"
"go.pedge.io/pkg/http"
"go.pedge.io/proto/rpclog"
"go.pedge.io/proto/version"

"golang.org/x/net/context"

"github.com/golang/glog"
"github.com/golang/protobuf/ptypes/duration"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
)
@@ -231,15 +231,22 @@ func logServerFinished(start time.Time, err error) {
protolion.Error(
&ServerFinished{
Error: err.Error(),
Duration: google_protobuf.DurationToProto(time.Since(start)),
Duration: durationToProto(time.Since(start)),
},
)
} else {
protolion.Info(
&ServerFinished{
Duration: google_protobuf.DurationToProto(time.Since(start)),
Duration: durationToProto(time.Since(start)),
},
)
}
glog.Flush()
}

func durationToProto(d time.Duration) *duration.Duration {
return &durationpb.Duration{
Seconds: int64(d) / int64(time.Second),
Nanos: int32(int64(d) % int64(time.Second)),
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -10,7 +10,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

"go.pedge.io/pb/go/google/protobuf"
"github.com/golang/protobuf/ptypes/wrappers"
)

var (
@@ -21,7 +21,7 @@ var (
// StreamingBytesServer represents a server for an rpc method of the form:
// rpc Foo(Bar) returns (stream google.protobuf.BytesValue) {}
type StreamingBytesServer interface {
Send(bytesValue *google_protobuf.BytesValue) error
Send(bytesValue *wrappers.BytesValue) error
}

// StreamingBytesServeCloser is a StreamingBytesServer with close.
@@ -33,7 +33,7 @@ type StreamingBytesServeCloser interface {
// StreamingBytesClient represents a client for an rpc method of the form:
// rpc Foo(Bar) returns (stream google.protobuf.BytesValue) {}
type StreamingBytesClient interface {
Recv() (*google_protobuf.BytesValue, error)
Recv() (*wrappers.BytesValue, error)
}

// StreamingBytesDuplexer is both a StreamingBytesClient and StreamingBytesServer.
@@ -70,30 +70,30 @@ func WriteToStreamingBytesServer(reader io.Reader, streamingBytesServer Streamin
}

// NewStreamingBytesClientHandler returns a StreamingBytesClientHandler for the given handleFunc.
func NewStreamingBytesClientHandler(handleFunc func(*google_protobuf.BytesValue) error) StreamingBytesClientHandler {
func NewStreamingBytesClientHandler(handleFunc func(*wrappers.BytesValue) error) StreamingBytesClientHandler {
return newStreamingBytesClientHandler(handleFunc)
}

// WriteFromStreamingBytesClient writes from the StreamingBytesClient to the io.Writer.
func WriteFromStreamingBytesClient(streamingBytesClient StreamingBytesClient, writer io.Writer) error {
return NewStreamingBytesClientHandler(
func(bytesValue *google_protobuf.BytesValue) error {
func(bytesValue *wrappers.BytesValue) error {
_, err := writer.Write(bytesValue.Value)
return err
},
).Handle(streamingBytesClient)
}

// RelayFromStreamingBytesClient relays *google_protobuf.BytesValues from the StreamingBytesClient to the StreamingBytesServer.
// RelayFromStreamingBytesClient relays *wrappers.BytesValues from the StreamingBytesClient to the StreamingBytesServer.
func RelayFromStreamingBytesClient(streamingBytesClient StreamingBytesClient, streamingBytesServer StreamingBytesServer) error {
return NewStreamingBytesClientHandler(
func(bytesValue *google_protobuf.BytesValue) error {
func(bytesValue *wrappers.BytesValue) error {
return streamingBytesServer.Send(bytesValue)
},
).Handle(streamingBytesClient)
}

// StreamingBytesRelayer represents both generated Clients and servers for streams of *google_protobuf.BytesValue.
// StreamingBytesRelayer represents both generated Clients and servers for streams of *wrappers.BytesValue.
type StreamingBytesRelayer interface {
StreamingBytesDuplexer
Header() (metadata.MD, error)
@@ -3,14 +3,14 @@ package protostream
import (
"io"

"go.pedge.io/pb/go/google/protobuf"
"github.com/golang/protobuf/ptypes/wrappers"
)

type streamingBytesClientHandler struct {
handleFunc func(*google_protobuf.BytesValue) error
handleFunc func(*wrappers.BytesValue) error
}

func newStreamingBytesClientHandler(handleFunc func(*google_protobuf.BytesValue) error) *streamingBytesClientHandler {
func newStreamingBytesClientHandler(handleFunc func(*wrappers.BytesValue) error) *streamingBytesClientHandler {
return &streamingBytesClientHandler{handleFunc}
}

@@ -9,15 +9,15 @@ import (

"google.golang.org/grpc/metadata"

"go.pedge.io/pb/go/google/protobuf"
"github.com/golang/protobuf/ptypes/wrappers"
"go.pedge.io/pkg/sync"
)

type streamingBytesRelayer struct {
ctx context.Context
header metadata.MD
trailer metadata.MD
values []*google_protobuf.BytesValue
values []*wrappers.BytesValue
cv *sync.Cond
closed pkgsync.VolatileBool
}
@@ -27,13 +27,13 @@ func newStreamingBytesRelayer(ctx context.Context) *streamingBytesRelayer {
ctx,
nil,
nil,
make([]*google_protobuf.BytesValue, 0),
make([]*wrappers.BytesValue, 0),
sync.NewCond(&sync.Mutex{}),
pkgsync.NewVolatileBool(false),
}
}

func (s *streamingBytesRelayer) Send(bytesValue *google_protobuf.BytesValue) error {
func (s *streamingBytesRelayer) Send(bytesValue *wrappers.BytesValue) error {
if bytesValue == nil {
return nil
}
@@ -44,12 +44,12 @@ func (s *streamingBytesRelayer) Send(bytesValue *google_protobuf.BytesValue) err
}
value := make([]byte, len(bytesValue.Value))
copy(value, bytesValue.Value)
s.values = append(s.values, &google_protobuf.BytesValue{Value: value})
s.values = append(s.values, &wrappers.BytesValue{Value: value})
s.cv.Signal()
return nil
}

func (s *streamingBytesRelayer) Recv() (*google_protobuf.BytesValue, error) {
func (s *streamingBytesRelayer) Recv() (*wrappers.BytesValue, error) {
s.cv.L.Lock()
for len(s.values) == 0 {
if s.closed.Value() {
@@ -1,6 +1,6 @@
package protostream

import "go.pedge.io/pb/go/google/protobuf"
import "github.com/golang/protobuf/ptypes/wrappers"

type streamingBytesWriter struct {
streamingBytesServer StreamingBytesServer
@@ -19,7 +19,7 @@ func (s *streamingBytesWriter) Write(p []byte) (int, error) {
return 0, nil
}
if err := s.streamingBytesServer.Send(
&google_protobuf.BytesValue{
&wrappers.BytesValue{
Value: p,
},
); err != nil {
Oops, something went wrong.

0 comments on commit 4e9a6df

Please sign in to comment.