Compare commits
105 Commits
Author | SHA1 | Date | |
---|---|---|---|
c7db8e0712 | |||
cef9bc9d4a | |||
e0ae6cf5ff | |||
0056cc9490 | |||
09352c9404 | |||
|
80922ed07f | ||
0e5bd5e085 | |||
|
f909014a4e | ||
17fac49685 | |||
|
17ef4ef505 | ||
bffde12d1e | |||
|
32a7c8ce20 | ||
c85da9d791 | |||
|
1f4689cfbd | ||
9d9b742ebf | |||
|
37934a0b44 | ||
9d44705f3a | |||
|
7d7d3d26fb | ||
|
c6392dabb2 | ||
|
01a58f22df | ||
6fe35e9a30 | |||
|
8bcfc52456 | ||
3b2227b187 | |||
|
4c74427ba1 | ||
4a98e11ef5 | |||
|
87650ba695 | ||
dc17f0b33e | |||
|
67c28d7e48 | ||
18a666fb19 | |||
|
b9453bcd4b | ||
17805825b7 | |||
|
75415304ca | ||
e7eb1cefc1 | |||
|
cddeee24e7 | ||
|
7d11073995 | ||
0f5a38032e | |||
|
c064150eb9 | ||
|
0f30cc299b | ||
|
b3ed79b730 | ||
|
19b32e0a24 | ||
|
c38a64cb50 | ||
|
08eb0c1cfe | ||
383c5be262 | |||
|
66258202ad | ||
f3dd212736 | |||
|
76520ad087 | ||
|
6255d89986 | ||
d66a397ba7 | |||
|
32fca93526 | ||
|
c1de2670ba | ||
|
d4f4f1839e | ||
864ec102bb | |||
|
425e60a67d | ||
cbd76cd7bd | |||
|
ed5a948b59 | ||
96d46f7815 | |||
|
e1041975e6 | ||
fe0e6f5522 | |||
|
ea109879b0 | ||
82ea33be6c | |||
|
88f2b58b9c | ||
81df4e95aa | |||
|
79001e76b0 | ||
2b662c4d4f | |||
|
569516c308 | ||
5d77eafc03 | |||
|
586eecf0e6 | ||
34bdee737e | |||
879a073ba6 | |||
1a7e8ce680 | |||
|
8fa468b8c2 | ||
998b5a44af | |||
|
d6932316e1 | ||
3da9cc6ef7 | |||
|
79b63854d3 | ||
b0eecc38ae | |||
|
529a3ff5d3 | ||
3983ac59d7 | |||
|
d39581edc1 | ||
a5b42ae219 | |||
|
8a1aa29241 | ||
36fc2dcd02 | |||
|
4193be57bc | ||
05d761efad | |||
|
b95dcc1d18 | ||
53576ab2c3 | |||
|
1445ef4cd0 | ||
a562e199c9 | |||
|
70c4d5dd26 | ||
5f4bb34d88 | |||
|
68687ee86b | ||
a26d1780e5 | |||
|
e9cf34ca20 | ||
1fddc708f0 | |||
|
d28c99ce2b | ||
f8e9773e4d | |||
|
6a27d5dbb2 | ||
b60cd2083c | |||
4bdcc0f817 | |||
db2e8fc393 | |||
|
c389e02622 | ||
|
6972116f32 | ||
016b3aa878 | |||
|
6673e7dd69 | ||
|
34a0caaeba |
20
.github/workflows/autoapprove.yml
vendored
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
name: "autoapprove"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
autoapprove:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: approve
|
||||
uses: hmarr/auto-approve-action@v3
|
||||
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||
id: approve
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: "automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'vtolstov'
|
||||
steps:
|
||||
- name: merge
|
||||
id: merge
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
13
.github/workflows/build.yml
vendored
13
.github/workflows/build.yml
vendored
@ -3,19 +3,20 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
@ -31,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
|
29
.github/workflows/codeql-analysis.yml
vendored
29
.github/workflows/codeql-analysis.yml
vendored
@ -9,7 +9,7 @@
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
name: "codeql"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
@ -17,16 +17,16 @@ on:
|
||||
types:
|
||||
- completed
|
||||
push:
|
||||
branches: [ master ]
|
||||
branches: [ master, v3 ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
branches: [ master, v3 ]
|
||||
schedule:
|
||||
- cron: '34 1 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
name: analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
@ -42,12 +42,15 @@ jobs:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: setup
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.17
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@ -57,8 +60,8 @@ jobs:
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
- name: autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@ -71,5 +74,5 @@ jobs:
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
- name: analyze
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
73
.github/workflows/dependabot-automerge.yml
vendored
73
.github/workflows/dependabot-automerge.yml
vendored
@ -1,66 +1,27 @@
|
||||
name: "prautomerge"
|
||||
name: "dependabot-automerge"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["prbuild"]
|
||||
types:
|
||||
- completed
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
Dependabot-Automerge:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
# Contains workaround to execute if dependabot updates the PR by checking for the base branch in the linked PR
|
||||
# The the github.event.workflow_run.event value is 'push' and not 'pull_request'
|
||||
# dont work with multiple workflows when last returns success
|
||||
if: >-
|
||||
github.event.workflow_run.conclusion == 'success'
|
||||
&& github.actor == 'dependabot[bot]'
|
||||
&& github.event.sender.login == 'dependabot[bot]'
|
||||
&& github.event.sender.type == 'Bot'
|
||||
&& (github.event.workflow_run.event == 'pull_request'
|
||||
|| (github.event.workflow_run.event == 'push' && github.event.workflow_run.pull_requests[0].base.ref == github.event.repository.default_branch ))
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- name: Approve Changes and Merge changes if label 'dependencies' is set
|
||||
uses: actions/github-script@v4
|
||||
- name: metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.3.6
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
console.log(context.payload.workflow_run);
|
||||
|
||||
var labelNames = await github.paginate(
|
||||
github.issues.listLabelsOnIssue,
|
||||
{
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
issue_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
},
|
||||
(response) => response.data.map(
|
||||
(label) => label.name
|
||||
)
|
||||
);
|
||||
|
||||
console.log(labelNames);
|
||||
|
||||
if (labelNames.includes('dependencies')) {
|
||||
console.log('Found label');
|
||||
|
||||
await github.pulls.createReview({
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
pull_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
event: 'APPROVE'
|
||||
});
|
||||
console.log('Approved PR');
|
||||
|
||||
await github.pulls.merge({
|
||||
repo: context.repo.repo,
|
||||
owner: context.repo.owner,
|
||||
pull_number: context.payload.workflow_run.pull_requests[0].number,
|
||||
});
|
||||
|
||||
console.log('Merged PR');
|
||||
}
|
||||
github-token: "${{ secrets.TOKEN }}"
|
||||
- name: merge
|
||||
id: merge
|
||||
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
||||
|
13
.github/workflows/pr.yml
vendored
13
.github/workflows/pr.yml
vendored
@ -3,19 +3,20 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
@ -31,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
uses: golangci/golangci-lint-action@v3.4.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
|
@ -3,8 +3,40 @@ package proto
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"go.unistack.org/micro/v4/codec"
|
||||
)
|
||||
|
||||
func TestFrame(t *testing.T) {
|
||||
s := &codec.Frame{Data: []byte("test")}
|
||||
|
||||
buf, err := NewCodec().Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(buf, []byte(`test`)) {
|
||||
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFrameFlatten(t *testing.T) {
|
||||
s := &struct {
|
||||
One string
|
||||
Name *codec.Frame `json:"name" codec:"flatten"`
|
||||
}{
|
||||
One: "xx",
|
||||
Name: &codec.Frame{Data: []byte("test")},
|
||||
}
|
||||
|
||||
buf, err := NewCodec().Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(buf, []byte(`test`)) {
|
||||
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadBody(t *testing.T) {
|
||||
t.Skip("skip as no proto")
|
||||
s := &struct {
|
||||
|
9
go.mod
9
go.mod
@ -1,8 +1,9 @@
|
||||
module github.com/unistack-org/micro-codec-proto/v3
|
||||
module go.unistack.org/micro-codec-proto/v4
|
||||
|
||||
go 1.16
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/unistack-org/micro/v3 v3.7.3
|
||||
google.golang.org/protobuf v1.27.1
|
||||
go.unistack.org/micro-proto/v4 v4.0.0
|
||||
go.unistack.org/micro/v4 v4.0.1
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
25
go.sum
25
go.sum
@ -1,25 +1,12 @@
|
||||
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
||||
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||
github.com/unistack-org/micro-proto v0.0.9 h1:KrWLS4FUX7UAWNAilQf70uad6ZPf/0EudeddCXllRVc=
|
||||
github.com/unistack-org/micro-proto v0.0.9/go.mod h1:Cckwmzd89gvS7ThxzZp9kQR/EOdksFQcsTAtDDyKwrg=
|
||||
github.com/unistack-org/micro/v3 v3.7.3 h1:7dCv7WuTYp47jZ/doVCXDNMnY75imprbmwSnmchTSJY=
|
||||
github.com/unistack-org/micro/v3 v3.7.3/go.mod h1:78vy7ggElJD+ayx8ruhJsY+SkGUupfR32LXrg1UObvg=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
go.unistack.org/micro-proto/v4 v4.0.0 h1:+TAwKSlx48eLsNO2E2cO0JLE8we1KU2AuWe9Q310FuU=
|
||||
go.unistack.org/micro-proto/v4 v4.0.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec=
|
||||
go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo=
|
||||
go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
|
82
proto.go
82
proto.go
@ -1,11 +1,12 @@
|
||||
// Package proto provides a proto codec
|
||||
package proto
|
||||
package proto // import "go.unistack.org/micro-codec-proto/v4"
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
||||
pb "go.unistack.org/micro-proto/v4/codec"
|
||||
"go.unistack.org/micro/v4/codec"
|
||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@ -13,55 +14,68 @@ type protoCodec struct {
|
||||
opts codec.Options
|
||||
}
|
||||
|
||||
var _ codec.Codec = &protoCodec{}
|
||||
|
||||
const (
|
||||
flattenTag = "flatten"
|
||||
)
|
||||
|
||||
func (c *protoCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error) {
|
||||
switch m := v.(type) {
|
||||
case nil:
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
options := c.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
||||
v = nv
|
||||
}
|
||||
|
||||
switch m := v.(type) {
|
||||
case *codec.Frame:
|
||||
return m.Data, nil
|
||||
case proto.Message:
|
||||
options := c.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
||||
if nm, ok := nv.(proto.Message); ok {
|
||||
m = nm
|
||||
}
|
||||
}
|
||||
return proto.Marshal(m)
|
||||
case *pb.Frame:
|
||||
return m.Data, nil
|
||||
}
|
||||
return nil, codec.ErrInvalidMessage
|
||||
|
||||
if _, ok := v.(proto.Message); !ok {
|
||||
return nil, codec.ErrInvalidMessage
|
||||
}
|
||||
|
||||
return proto.Marshal(v.(proto.Message))
|
||||
}
|
||||
|
||||
func (c *protoCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) error {
|
||||
if len(d) == 0 {
|
||||
if v == nil || len(d) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
options := c.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
||||
v = nv
|
||||
}
|
||||
|
||||
switch m := v.(type) {
|
||||
case nil:
|
||||
return nil
|
||||
case *codec.Frame:
|
||||
m.Data = d
|
||||
case proto.Message:
|
||||
options := c.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
||||
if nm, ok := nv.(proto.Message); ok {
|
||||
m = nm
|
||||
}
|
||||
}
|
||||
return proto.Unmarshal(d, m)
|
||||
return nil
|
||||
case *pb.Frame:
|
||||
m.Data = d
|
||||
return nil
|
||||
}
|
||||
return codec.ErrInvalidMessage
|
||||
|
||||
if _, ok := v.(proto.Message); !ok {
|
||||
return codec.ErrInvalidMessage
|
||||
}
|
||||
|
||||
return proto.Unmarshal(d, v.(proto.Message))
|
||||
}
|
||||
|
||||
func (c *protoCodec) ReadHeader(conn io.Reader, m *codec.Message, t codec.MessageType) error {
|
||||
|
Loading…
Reference in New Issue
Block a user