Ejemplo n.º 1
0
func (pu *protoUnmarshaler) UnmarshalPayload(msg Message) error {
	result := proto.Message(nil)

	_body := msg.Body()
	if bodyT := reflect.TypeOf(_body); bodyT != nil && bodyT.AssignableTo(pu.T) {
		// The message already has an appropriate body; unmarshal into it
		result = _body.(proto.Message)
	} else {
		// No body (or an inappropriate type); overwrite with a new object
		result = reflect.New(pu.T.Elem()).Interface().(proto.Message)
	}

	err := proto.Unmarshal(msg.Payload(), result)
	if err == nil {
		msg.SetBody(result)
	}
	return err
}
Ejemplo n.º 2
0
)

var (
	addrHTTP = flag.String("addr_http", "", "deprecated")
	addrAPI  = flag.String("addr_api", "", "deprecated")
)

// ProtoMessage is the same as proto.Message. It is defined here because user
// code cannot import package proto.
type ProtoMessage interface {
	Reset()
	String() string
	ProtoMessage()
}

var _ ProtoMessage = proto.Message(ProtoMessage(nil))

type CallOptions struct {
	Timeout time.Duration // if non-zero, overrides RPC default
}

// errorCodeMaps is a map of service name to the error code map for the service.
var errorCodeMaps = make(map[string]map[int32]string)

// RegisterErrorCodeMap is called from API implementations to register their
// error code map. This should only be called from init functions.
func RegisterErrorCodeMap(service string, m map[int32]string) {
	errorCodeMaps[service] = m
}

type timeoutCodeKey struct {