Skip to content

Commit

Permalink
refactor: secconf chain support
Browse files Browse the repository at this point in the history
  • Loading branch information
hui.wang committed Jan 5, 2022
1 parent 3255bf8 commit fde9667
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions secconf/codec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package secconf

import "errors"

type Codec interface {
Apply(data []byte) ([]byte, error)
}
Expand All @@ -22,29 +20,3 @@ func (c CodecFuncChain) Apply(data []byte) (out []byte, err error) {
type CodecFunc func(data []byte) ([]byte, error)

func (f CodecFunc) Apply(data []byte) ([]byte, error) { return f(data) }

func newInvalidCodec(name string) Codec {
return CodecFunc(func(data []byte) ([]byte, error) {
return data, errors.New("invalid codec func for " + name)
})
}

var decoderRegister = make(map[string]Codec)
var encoderRegister = make(map[string]Codec)

func RegisterDecoder(name string, cf Codec) { decoderRegister[name] = cf }
func RegisterEncoder(name string, cf Codec) { encoderRegister[name] = cf }

func Decoder(name string) Codec {
if cf, ok := decoderRegister[name]; ok {
return cf
}
return newInvalidCodec(name)
}

func Encoder(name string) Codec {
if cf, ok := encoderRegister[name]; ok {
return cf
}
return newInvalidCodec(name)
}

0 comments on commit fde9667

Please sign in to comment.