Commit 3ba63bda authored by AlexStocks's avatar AlexStocks

Add: rpc pb

parent 7c02e44e
......@@ -3,22 +3,19 @@ package rpc
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"reflect"
"unsafe"
)
import (
log "github.com/AlexStocks/log4go"
proto "github.com/gogo/protobuf/proto"
pb "github.com/golang/protobuf/proto"
"github.com/json-iterator/go"
jerrors "github.com/juju/errors"
)
import (
log "github.com/AlexStocks/log4go"
)
////////////////////////////////////////////
// getty command
////////////////////////////////////////////
......@@ -129,14 +126,20 @@ type Codec interface {
// JSONCodec uses json marshaler and unmarshaler.
type JSONCodec struct{}
var (
jsonstd = jsoniter.ConfigCompatibleWithStandardLibrary
)
// Encode encodes an object into slice of bytes.
func (c JSONCodec) Encode(i interface{}) ([]byte, error) {
return json.Marshal(i)
// return json.Marshal(i)
return jsonstd.Marshal(i)
}
// Decode decodes an object from slice of bytes.
func (c JSONCodec) Decode(data []byte, i interface{}) error {
return json.Unmarshal(data, i)
// return json.Unmarshal(data, i)
return jsonstd.Unmarshal(data, i)
}
// PBCodec uses protobuf marshaler and unmarshaler.
......@@ -298,7 +301,7 @@ func (p *GettyPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
type GettyRPCHeaderLenType uint16
//easyjson:json
// easyjson:json
type GettyRPCRequestHeader struct {
Service string
Method string
......
#!/usr/bin/env bash
# ******************************************************
# DESC :
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2017-09-04 22:53
# FILE : pb.sh
# ******************************************************
mkdir ./src
# descriptor.proto
gopath=~/test/golang/lib/src/github.com/gogo/protobuf/protobuf
# If you are using any gogo.proto extensions you will need to specify the
# proto_path to include the descriptor.proto and gogo.proto.
# gogo.proto is located in github.com/gogo/protobuf/gogoproto
gogopath=~/test/golang/lib/src/
# protoc -I=$gopath:$gogopath:/Users/alex/test/golang/lib/src/github.com/AlexStocks/goext/database/redis/:./ --gogoslick_out=Mredis_meta.proto="github.com/AlexStocks/goext/database/redis":../app/ cluster_meta.proto
# protoc -I=$gopath:$gogopath:/Users/alex/test/golang/lib/src/github.com/AlexStocks/goext/database/redis/:./ --gogoslick_out=Mredis_meta.proto="github.com/AlexStocks/goext/database/redis":../app/ response.proto
# protoc -I=$gopath:$gogopath:./ --gogoslick_out=Mrole.proto="github.com/AlexStocks/goext/database/registry":./src/ service.proto
protoc -I=$gopath:$gogopath:./ --gogoslick_out=./src/ rpc.proto
syntax = "proto2";
package rpc;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option (gogoproto.gostring_all) = true;
option (gogoproto.equal_all) = true;
option (gogoproto.verbose_equal_all) = true;
// option (gogoproto.goproto_stringer_all) = false;
// option (gogoproto.stringer_all) = true;
// option (gogoproto.populate_all) = true;
// option (gogoproto.testgen_all) = true;
// option (gogoproto.benchgen_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.goproto_enum_prefix_all) = false;
//////////////////////////////////////////
// Request Header
//////////////////////////////////////////
enum CallType {
CT_UNKOWN = 0;
CT_OneWay = 1;
CT_TwoWay = 2;
CT_TwoWayNoReply = 3;
}
message GettyRPCRequestHeader {
optional string Service = 1 [(gogoproto.nullable) = false];
optional string Method = 2 [(gogoproto.nullable) = false];
optional CallType CallType = 3 [(gogoproto.nullable) = false];
}
......@@ -3,11 +3,11 @@ package rpc
import (
"bytes"
"reflect"
)
import (
"github.com/AlexStocks/getty"
log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors"
)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment