drop old proto
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
c3f2ea1d13
commit
db8c944ba9
3
go.mod
3
go.mod
@ -1,9 +1,8 @@
|
|||||||
module github.com/unistack-org/micro-codec-jsonpb/v3
|
module github.com/unistack-org/micro-codec-jsonpb/v3
|
||||||
|
|
||||||
go 1.15
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/golang/protobuf v1.5.1
|
|
||||||
github.com/unistack-org/micro/v3 v3.2.24
|
github.com/unistack-org/micro/v3 v3.2.24
|
||||||
google.golang.org/protobuf v1.26.0
|
google.golang.org/protobuf v1.26.0
|
||||||
)
|
)
|
||||||
|
3
go.sum
3
go.sum
@ -1,8 +1,7 @@
|
|||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
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/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/golang/protobuf v1.5.1 h1:jAbXjIeW2ZSW2AwFxlGTDoc2CjI2XujLkV3ArsZFCvc=
|
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
|
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
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/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||||
|
23
jsonpb.go
23
jsonpb.go
@ -2,14 +2,9 @@
|
|||||||
package jsonpb
|
package jsonpb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
// nolint: staticcheck
|
|
||||||
oldjsonpb "github.com/golang/protobuf/jsonpb"
|
|
||||||
// nolint: staticcheck
|
|
||||||
oldproto "github.com/golang/protobuf/proto"
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"github.com/unistack-org/micro/v3/codec"
|
||||||
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
@ -27,15 +22,6 @@ var (
|
|||||||
DiscardUnknown: false,
|
DiscardUnknown: false,
|
||||||
AllowPartial: false,
|
AllowPartial: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
OldJsonpbMarshaler = oldjsonpb.Marshaler{
|
|
||||||
OrigName: true,
|
|
||||||
EmitDefaults: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
OldJsonpbUnmarshaler = oldjsonpb.Unmarshaler{
|
|
||||||
AllowUnknownFields: false,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type jsonpbCodec struct{}
|
type jsonpbCodec struct{}
|
||||||
@ -48,9 +34,6 @@ func (c *jsonpbCodec) Marshal(v interface{}) ([]byte, error) {
|
|||||||
return m.Data, nil
|
return m.Data, nil
|
||||||
case proto.Message:
|
case proto.Message:
|
||||||
return JsonpbMarshaler.Marshal(m)
|
return JsonpbMarshaler.Marshal(m)
|
||||||
case oldproto.Message:
|
|
||||||
buf, err := OldJsonpbMarshaler.MarshalToString(m)
|
|
||||||
return []byte(buf), err
|
|
||||||
}
|
}
|
||||||
return nil, codec.ErrInvalidMessage
|
return nil, codec.ErrInvalidMessage
|
||||||
}
|
}
|
||||||
@ -67,8 +50,6 @@ func (c *jsonpbCodec) Unmarshal(d []byte, v interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
case proto.Message:
|
case proto.Message:
|
||||||
return JsonpbUnmarshaler.Unmarshal(d, m)
|
return JsonpbUnmarshaler.Unmarshal(d, m)
|
||||||
case oldproto.Message:
|
|
||||||
return OldJsonpbUnmarshaler.Unmarshal(bytes.NewReader(d), m)
|
|
||||||
}
|
}
|
||||||
return codec.ErrInvalidMessage
|
return codec.ErrInvalidMessage
|
||||||
}
|
}
|
||||||
@ -87,8 +68,6 @@ func (c *jsonpbCodec) ReadBody(conn io.Reader, b interface{}) error {
|
|||||||
}
|
}
|
||||||
m.Data = buf
|
m.Data = buf
|
||||||
return nil
|
return nil
|
||||||
case oldproto.Message:
|
|
||||||
return OldJsonpbUnmarshaler.Unmarshal(conn, m)
|
|
||||||
case proto.Message:
|
case proto.Message:
|
||||||
buf, err := ioutil.ReadAll(conn)
|
buf, err := ioutil.ReadAll(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -106,8 +85,6 @@ func (c *jsonpbCodec) Write(conn io.Writer, m *codec.Message, b interface{}) err
|
|||||||
case *codec.Frame:
|
case *codec.Frame:
|
||||||
_, err := conn.Write(m.Data)
|
_, err := conn.Write(m.Data)
|
||||||
return err
|
return err
|
||||||
case oldproto.Message:
|
|
||||||
return OldJsonpbMarshaler.Marshal(conn, m)
|
|
||||||
case proto.Message:
|
case proto.Message:
|
||||||
buf, err := JsonpbMarshaler.Marshal(m)
|
buf, err := JsonpbMarshaler.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user