Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
3ba63bda
Commit
3ba63bda
authored
Aug 06, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add: rpc pb
parent
7c02e44e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
619 additions
and
10 deletions
+619
-10
codec.go
rpc/codec.go
+11
-8
pb.sh
rpc/proto/pb.sh
+24
-0
rpc.proto
rpc/proto/rpc.proto
+37
-0
readwriter.go
rpc/readwriter.go
+2
-2
rpc.pb.go
rpc/rpc.pb.go
+545
-0
No files found.
rpc/codec.go
View file @
3ba63bda
...
...
@@ -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
...
...
rpc/proto/pb.sh
0 → 100644
View file @
3ba63bda
#!/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
rpc/proto/rpc.proto
0 → 100644
View file @
3ba63bda
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
];
}
rpc/readwriter.go
View file @
3ba63bda
...
...
@@ -3,11 +3,11 @@ package rpc
import
(
"bytes"
"reflect"
)
import
(
"github.com/AlexStocks/getty"
log
"github.com/AlexStocks/log4go"
jerrors
"github.com/juju/errors"
)
...
...
rpc/rpc.pb.go
0 → 100644
View file @
3ba63bda
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment