Compare commits
110 Commits
Author | SHA1 | Date | |
---|---|---|---|
43b5b349e6 | |||
efb75b8357 | |||
3dac202602 | |||
|
cf29bc78a2 | ||
31ea6d6989 | |||
e09c864070 | |||
00c28b81e5 | |||
1f0e408b78 | |||
|
0ac4b429a3 | ||
6a88898e25 | |||
|
3620958f74 | ||
03e943c7c9 | |||
|
1b2dc672a8 | ||
ba4dd2c1da | |||
|
5fde3800b1 | ||
c978431c88 | |||
|
3a0ba2b207 | ||
|
145db4c674 | ||
1c6dfdf868 | |||
|
8916756eef | ||
|
4e39b338ce | ||
4f5fefb349 | |||
|
c9a72b6bbb | ||
637237d03f | |||
|
9d2854abc0 | ||
d3bbd7ebf9 | |||
|
541b134279 | ||
5dc7ea65b8 | |||
|
f685e7fa0c | ||
2d4e273b1c | |||
|
8190f26e01 | ||
e4d991e7b4 | |||
|
8efe34eb60 | ||
|
df5d2c2652 | ||
b7e1d16afd | |||
|
2829fb8abe | ||
a18a1e4405 | |||
|
2c0e231859 | ||
|
4355c74749 | ||
|
bd07bd2070 | ||
|
24247e3b5c | ||
|
81b5929d9a | ||
|
292de480d9 | ||
28d7a6d7cb | |||
|
8350690b49 | ||
9d28498e84 | |||
|
6aec43a188 | ||
|
2223d324c5 | ||
b98f347e85 | |||
|
fc8eafbf70 | ||
|
2bf0f09fa3 | ||
|
f3a61bf1ce | ||
068ffb364a | |||
|
f6c045e9c2 | ||
ba68dcbbca | |||
|
4569fd398b | ||
98445de252 | |||
|
4b2d61276f | ||
f5a0db096b | |||
|
2f6a61cca4 | ||
bdb68a0906 | |||
|
b5c2eb0b0b | ||
c8ae610f6f | |||
|
8c437ce466 | ||
d7f756cbcf | |||
fa833d6541 | |||
c46d6b6b8c | |||
|
bf00985f88 | ||
c4b61677ef | |||
|
0d0f9d1b6b | ||
098b129ad4 | |||
|
aec0e3c1f9 | ||
0fecbd6978 | |||
|
414cd4abf9 | ||
fc5feff3e8 | |||
|
9770e3b2f3 | ||
c1b9af1d7a | |||
|
ed31f4f8c8 | ||
0e02a6ca2f | |||
|
a3906fe9e9 | ||
4a5d7b0f48 | |||
|
e5fcc4b41d | ||
4413229461 | |||
|
2447a21f11 | ||
127b5a7e11 | |||
|
03d15a54dc | ||
2cf52ab5f0 | |||
|
d45277db32 | ||
5495d0e182 | |||
|
f4dadd446c | ||
8f552b7942 | |||
|
ba2832a200 | ||
45848f11b7 | |||
|
ba00a5daa3 | ||
6297962aa0 | |||
933de678cd | |||
a67f2bb719 | |||
|
04fa09bd63 | ||
|
555ea51811 | ||
3ba495e1f1 | |||
|
4fd05f2da8 | ||
|
91c80cb527 | ||
1cf78d0bab | |||
6229ae0c59 | |||
1563b29dab | |||
93b3c04df2 | |||
afa62f60ae | |||
|
0670977d5c | ||
d6c973065b | |||
3712a99f8d |
29
.gitea/workflows/job_lint.yml
Normal file
29
.gitea/workflows/job_lint.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
name: lint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
filter: 'blob:none'
|
||||
- name: setup go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
cache-dependency-path: "**/*.sum"
|
||||
go-version: 'stable'
|
||||
- name: setup deps
|
||||
run: go get -v ./...
|
||||
- name: run lint
|
||||
uses: https://github.com/golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: 'latest'
|
34
.gitea/workflows/job_test.yml
Normal file
34
.gitea/workflows/job_test.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
name: test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
filter: 'blob:none'
|
||||
- name: setup go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
cache-dependency-path: "**/*.sum"
|
||||
go-version: 'stable'
|
||||
- name: setup deps
|
||||
run: go get -v ./...
|
||||
- name: run test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
53
.gitea/workflows/job_tests.yml
Normal file
53
.gitea/workflows/job_tests.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
name: test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
filter: 'blob:none'
|
||||
- name: checkout tests
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: master
|
||||
filter: 'blob:none'
|
||||
repository: unistack-org/micro-tests
|
||||
path: micro-tests
|
||||
- name: setup go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
cache-dependency-path: "**/*.sum"
|
||||
go-version: 'stable'
|
||||
- name: setup go work
|
||||
env:
|
||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
||||
run: |
|
||||
go work init
|
||||
go work use .
|
||||
go work use micro-tests
|
||||
- name: setup deps
|
||||
env:
|
||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
||||
run: go get -v ./...
|
||||
- name: run tests
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
||||
run: |
|
||||
cd micro-tests
|
||||
go test -mod readonly -v ./... || true
|
19
.github/renovate.json
vendored
19
.github/renovate.json
vendored
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"packageRules": [
|
||||
{
|
||||
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
|
||||
"automerge": true
|
||||
},
|
||||
{
|
||||
"groupName": "all deps",
|
||||
"separateMajorMinor": true,
|
||||
"groupSlug": "all",
|
||||
"packagePatterns": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
13
.github/stale.sh
vendored
13
.github/stale.sh
vendored
@@ -1,13 +0,0 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
export PATH=$PATH:$(pwd)/bin
|
||||
export GO111MODULE=on
|
||||
export GOBIN=$(pwd)/bin
|
||||
|
||||
#go get github.com/rvflash/goup@v0.4.1
|
||||
|
||||
#goup -v ./...
|
||||
#go get github.com/psampaz/go-mod-outdated@v0.6.0
|
||||
go list -u -m -mod=mod -json all | go-mod-outdated -update -direct -ci || true
|
||||
|
||||
#go list -u -m -json all | go-mod-outdated -update
|
46
.github/workflows/build.yml
vendored
46
.github/workflows/build.yml
vendored
@@ -1,46 +0,0 @@
|
||||
name: build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: ${{ runner.os }}-go-
|
||||
- name: deps
|
||||
run: go get -v -t -d ./...
|
||||
- name: test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
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.
|
||||
version: v1.30
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
46
.github/workflows/pr.yml
vendored
46
.github/workflows/pr.yml
vendored
@@ -1,46 +0,0 @@
|
||||
name: prbuild
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: ${{ runner.os }}-go-
|
||||
- name: deps
|
||||
run: go get -v -t -d ./...
|
||||
- name: test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
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.
|
||||
version: v1.30
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
@@ -3,16 +3,36 @@ package xml
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
)
|
||||
|
||||
func TestReadBody(t *testing.T) {
|
||||
s := &struct {
|
||||
Name string
|
||||
}{}
|
||||
c := NewCodec()
|
||||
b := bytes.NewReader(nil)
|
||||
err := c.ReadBody(b, s)
|
||||
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 `xml:"name" codec:"flatten"`
|
||||
}{
|
||||
One: "xx",
|
||||
Name: &codec.Frame{Data: []byte("test")},
|
||||
}
|
||||
|
||||
buf, err := NewCodec(codec.Flatten(true)).Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(buf, []byte(`test`)) {
|
||||
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
||||
}
|
||||
}
|
||||
|
16
go.mod
16
go.mod
@@ -1,5 +1,15 @@
|
||||
module github.com/unistack-org/micro-codec-xml/v3
|
||||
module go.unistack.org/micro-codec-xml/v3
|
||||
|
||||
go 1.16
|
||||
go 1.21
|
||||
|
||||
require github.com/unistack-org/micro/v3 v3.3.19
|
||||
toolchain go1.23.4
|
||||
|
||||
require (
|
||||
go.unistack.org/micro-proto/v3 v3.4.1
|
||||
go.unistack.org/micro/v3 v3.10.88
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
google.golang.org/protobuf v1.35.2 // indirect
|
||||
)
|
||||
|
24
go.sum
24
go.sum
@@ -1,16 +1,8 @@
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
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/v3 v3.3.19 h1:x0bl4H+IZvdHHKfA8qMcox9W92+e7rtbqgRfQPoP79w=
|
||||
github.com/unistack-org/micro/v3 v3.3.19/go.mod h1:LXmPfbJnJNvL0kQs8HfnkV3Wya2Wb+C7keVq++RCZnk=
|
||||
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=
|
||||
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=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
|
||||
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
|
||||
go.unistack.org/micro/v3 v3.10.88 h1:MxlzP+77Y6Kphb3lzHxROL4XfE/WdCQMQpnPv4D9Z8U=
|
||||
go.unistack.org/micro/v3 v3.10.88/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
||||
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
|
5
golangci.yml
Normal file
5
golangci.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
run:
|
||||
concurrency: 8
|
||||
deadline: 5m
|
||||
issues-exit-code: 1
|
||||
tests: true
|
137
xml.go
137
xml.go
@@ -1,91 +1,128 @@
|
||||
// Package xml provides a xml codec
|
||||
package xml
|
||||
package xml // import "go.unistack.org/micro-codec-xml/v3"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
||||
pb "go.unistack.org/micro-proto/v3/codec"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||
)
|
||||
|
||||
type xmlCodec struct{}
|
||||
var _ codec.Codec = &xmlCodec{}
|
||||
|
||||
type xmlCodec struct {
|
||||
opts codec.Options
|
||||
}
|
||||
|
||||
const (
|
||||
flattenTag = "flatten"
|
||||
)
|
||||
|
||||
func (c *xmlCodec) Marshal(v interface{}) ([]byte, error) {
|
||||
switch m := v.(type) {
|
||||
case nil:
|
||||
func (c *xmlCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
case *codec.Frame:
|
||||
return m.Data, nil
|
||||
}
|
||||
|
||||
if nv, nerr := rutil.StructFieldByTag(v, codec.DefaultTagName, flattenTag); nerr == nil {
|
||||
v = nv
|
||||
options := c.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if options.Flatten {
|
||||
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 *pb.Frame:
|
||||
return m.Data, nil
|
||||
case codec.RawMessage:
|
||||
return []byte(m), nil
|
||||
case *codec.RawMessage:
|
||||
return []byte(*m), nil
|
||||
}
|
||||
|
||||
return xml.Marshal(v)
|
||||
}
|
||||
|
||||
func (c *xmlCodec) Unmarshal(b []byte, v interface{}) error {
|
||||
func (c *xmlCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) error {
|
||||
if len(b) == 0 || v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if m, ok := v.(*codec.Frame); ok {
|
||||
options := c.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if options.Flatten {
|
||||
if nv, nerr := rutil.StructFieldByTag(v, options.TagName, flattenTag); nerr == nil {
|
||||
v = nv
|
||||
}
|
||||
}
|
||||
|
||||
switch m := v.(type) {
|
||||
case *codec.Frame:
|
||||
m.Data = b
|
||||
return nil
|
||||
}
|
||||
|
||||
if nv, nerr := rutil.StructFieldByTag(v, codec.DefaultTagName, flattenTag); nerr == nil {
|
||||
v = nv
|
||||
}
|
||||
|
||||
return xml.Unmarshal(b, v)
|
||||
}
|
||||
|
||||
func (c *xmlCodec) ReadHeader(conn io.Reader, m *codec.Message, t codec.MessageType) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *xmlCodec) ReadBody(conn io.Reader, v interface{}) error {
|
||||
if v == nil {
|
||||
case *pb.Frame:
|
||||
m.Data = b
|
||||
return nil
|
||||
case *codec.RawMessage:
|
||||
*m = append((*m)[0:0], b...)
|
||||
return nil
|
||||
case codec.RawMessage:
|
||||
copy(m, b)
|
||||
return nil
|
||||
}
|
||||
|
||||
buf, err := io.ReadAll(conn)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if len(buf) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return c.Unmarshal(buf, v)
|
||||
return xml.NewDecoder(newReader(b)).Decode(v)
|
||||
}
|
||||
|
||||
func (c *xmlCodec) Write(conn io.Writer, m *codec.Message, v interface{}) error {
|
||||
if v == nil {
|
||||
return nil
|
||||
type reader struct {
|
||||
s []byte
|
||||
i int64 // current reading index
|
||||
prevRune int // index of previous rune; or < 0
|
||||
skip bool
|
||||
}
|
||||
|
||||
func newReader(b []byte) io.Reader {
|
||||
return &reader{b, 0, -1, false}
|
||||
}
|
||||
|
||||
var (
|
||||
srcP = []byte(`version="1.1"`)
|
||||
srcL = len(srcP)
|
||||
dstP = []byte(`version="1.0"`)
|
||||
)
|
||||
|
||||
func (r *reader) Read(b []byte) (n int, err error) {
|
||||
if r.i >= int64(len(r.s)) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
r.prevRune = -1
|
||||
n = copy(b, r.s[r.i:])
|
||||
if !r.skip {
|
||||
if idx := bytes.Index(b, srcP); idx > 0 {
|
||||
copy(b[idx:idx+srcL], dstP)
|
||||
r.skip = true
|
||||
}
|
||||
}
|
||||
|
||||
buf, err := c.Marshal(v)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if len(buf) == 0 {
|
||||
return codec.ErrInvalidMessage
|
||||
}
|
||||
|
||||
_, err = conn.Write(buf)
|
||||
return err
|
||||
r.i += int64(n)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *xmlCodec) String() string {
|
||||
return "xml"
|
||||
}
|
||||
|
||||
func NewCodec() codec.Codec {
|
||||
return &xmlCodec{}
|
||||
func NewCodec(opts ...codec.Option) *xmlCodec {
|
||||
return &xmlCodec{opts: codec.NewOptions(opts...)}
|
||||
}
|
||||
|
Reference in New Issue
Block a user