1- package binary
1+ package codecs
22
33import (
44 "reflect"
55
6+ "github.com/encodingx/binary/internal/codecs/metadata"
67 "github.com/encodingx/binary/internal/validation"
78)
89
9- type codec struct {
10- formatMetadataCache map [reflect.Type ]formatMetadata
10+ type Codec struct {
11+ formatMetadataCache map [reflect.Type ]metadata. FormatMetadata
1112}
1213
13- func newCodec () (c codec ) {
14- c = codec {
15- formatMetadataCache : make (map [reflect.Type ]formatMetadata ),
14+ func NewCodec () (c Codec ) {
15+ c = Codec {
16+ formatMetadataCache : make (map [reflect.Type ]metadata. FormatMetadata ),
1617 }
1718
1819 return
1920}
2021
21- func (c codec ) formatMetadataFromTypeReflection (reflection reflect.Type ) (
22- format formatMetadata , e error ,
22+ func (c Codec ) formatMetadataFromTypeReflection (reflection reflect.Type ) (
23+ format metadata. FormatMetadata , e error ,
2324) {
2425 var (
2526 inCache bool
@@ -43,7 +44,7 @@ func (c codec) formatMetadataFromTypeReflection(reflection reflect.Type) (
4344 return
4445 }
4546
46- format , e = newFormatMetadataFromTypeReflection (
47+ format , e = metadata . NewFormatMetadataFromTypeReflection (
4748 reflection .Elem (),
4849 )
4950 if e != nil {
@@ -55,8 +56,8 @@ func (c codec) formatMetadataFromTypeReflection(reflection reflect.Type) (
5556 return
5657}
5758
58- func (c codec ) newOperation (iface interface {}) (
59- operation codecOperation , e error ,
59+ func (c Codec ) NewOperation (iface interface {}) (
60+ operation CodecOperation , e error ,
6061) {
6162 operation .format , e = c .formatMetadataFromTypeReflection (
6263 reflect .TypeOf (iface ),
@@ -70,21 +71,21 @@ func (c codec) newOperation(iface interface{}) (
7071 return
7172}
7273
73- type codecOperation struct {
74- format formatMetadata
74+ type CodecOperation struct {
75+ format metadata. FormatMetadata
7576 valueReflection reflect.Value
7677}
7778
78- func (c codecOperation ) marshal () (bytes []byte , e error ) {
79- bytes = c .format .marshal (c .valueReflection )
79+ func (c CodecOperation ) Marshal () (bytes []byte , e error ) {
80+ bytes = c .format .Marshal (c .valueReflection )
8081
8182 return
8283}
8384
84- func (c codecOperation ) unmarshal (bytes []byte ) (e error ) {
85- if len (bytes ) != c .format .lengthInBytes {
85+ func (c CodecOperation ) Unmarshal (bytes []byte ) (e error ) {
86+ if len (bytes ) != c .format .LengthInBytes () {
8687 e = validation .NewLengthOfByteSliceNotEqualToFormatLengthError (
87- uint (c .format .lengthInBytes ),
88+ uint (c .format .LengthInBytes () ),
8889 uint (len (bytes )),
8990 )
9091
@@ -95,7 +96,7 @@ func (c codecOperation) unmarshal(bytes []byte) (e error) {
9596 return
9697 }
9798
98- c .format .unmarshal (bytes , c .valueReflection )
99+ c .format .Unmarshal (bytes , c .valueReflection )
99100
100101 return
101102}
0 commit comments