1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-24 23:16:47 +02:00

#66 Make extension api like the java version

This commit is contained in:
Tao Wen
2017-06-20 10:41:54 +08:00
parent 499412ec4c
commit be221df432
4 changed files with 229 additions and 220 deletions

View File

@ -12,7 +12,6 @@ import (
type Config struct {
IndentionStep int
MarshalFloatWith6Digits bool
SupportUnexportedStructFields bool
EscapeHtml bool
SortMapKeys bool
UseNumber bool
@ -24,7 +23,7 @@ type frozenConfig struct {
indentionStep int
decoderCache unsafe.Pointer
encoderCache unsafe.Pointer
extensions []ExtensionFunc
extensions []Extension
streamPool chan *Stream
iteratorPool chan *Iterator
}
@ -65,9 +64,6 @@ func (cfg Config) Froze() *frozenConfig {
if cfg.MarshalFloatWith6Digits {
frozenConfig.marshalFloatWith6Digits()
}
if cfg.SupportUnexportedStructFields {
frozenConfig.supportUnexportedStructFields()
}
if cfg.EscapeHtml {
frozenConfig.escapeHtml()
}
@ -88,17 +84,10 @@ func (cfg *frozenConfig) useNumber() {
}})
}
// RegisterExtension can register a custom extension
func (cfg *frozenConfig) registerExtension(extension ExtensionFunc) {
func (cfg *frozenConfig) registerExtension(extension Extension) {
cfg.extensions = append(cfg.extensions, extension)
}
func (cfg *frozenConfig) supportUnexportedStructFields() {
cfg.registerExtension(func(type_ reflect.Type, field *reflect.StructField) ([]string, EncoderFunc, DecoderFunc) {
return []string{field.Name}, nil, nil
})
}
type lossyFloat32Encoder struct {
}