add codec.RawMessage support
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
3dac202602
commit
9498734307
11
go.mod
11
go.mod
@ -1,10 +1,15 @@
|
|||||||
module go.unistack.org/micro-codec-xml/v3
|
module go.unistack.org/micro-codec-xml/v3
|
||||||
|
|
||||||
go 1.16
|
go 1.21
|
||||||
|
|
||||||
|
toolchain go1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/imdario/mergo v0.3.13 // indirect
|
|
||||||
go.unistack.org/micro-proto/v3 v3.4.1
|
go.unistack.org/micro-proto/v3 v3.4.1
|
||||||
go.unistack.org/micro/v3 v3.10.88
|
go.unistack.org/micro/v3 v3.10.88
|
||||||
google.golang.org/protobuf v1.34.2 // indirect
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.35.2 // indirect
|
||||||
)
|
)
|
||||||
|
10
xml.go
10
xml.go
@ -40,6 +40,10 @@ func (c *xmlCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error)
|
|||||||
return m.Data, nil
|
return m.Data, nil
|
||||||
case *pb.Frame:
|
case *pb.Frame:
|
||||||
return m.Data, nil
|
return m.Data, nil
|
||||||
|
case codec.RawMessage:
|
||||||
|
return []byte(m), nil
|
||||||
|
case *codec.RawMessage:
|
||||||
|
return []byte(*m), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return xml.Marshal(v)
|
return xml.Marshal(v)
|
||||||
@ -68,6 +72,12 @@ func (c *xmlCodec) Unmarshal(b []byte, v interface{}, opts ...codec.Option) erro
|
|||||||
case *pb.Frame:
|
case *pb.Frame:
|
||||||
m.Data = b
|
m.Data = b
|
||||||
return nil
|
return nil
|
||||||
|
case *codec.RawMessage:
|
||||||
|
*m = append((*m)[0:0], b...)
|
||||||
|
return nil
|
||||||
|
case codec.RawMessage:
|
||||||
|
copy(m, b)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return xml.Unmarshal(b, v)
|
return xml.Unmarshal(b, v)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user