add codec.RawMessage support
All checks were successful
test / test (push) Successful in 3m39s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2024-12-23 20:50:14 +03:00
parent fdaef26e35
commit 854b0ea94e
3 changed files with 20 additions and 157 deletions

12
toml.go
View File

@@ -1,5 +1,5 @@
// Package toml provides a toml codec
package toml // import "go.unistack.org/micro-codec-toml/v3"
package toml
import (
"bytes"
@@ -37,6 +37,10 @@ func (c *tomlCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, error)
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
}
buf := bytes.NewBuffer(nil)
@@ -71,6 +75,12 @@ func (c *tomlCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) err
case *pb.Frame:
m.Data = d
return nil
case *codec.RawMessage:
*m = append((*m)[0:0], d...)
return nil
case codec.RawMessage:
copy(m, d)
return nil
}
return toml.Unmarshal(d, v)