francoispqt / gojay

high performance JSON encoder/decoder with stream API for Golang
MIT License
2.11k stars 112 forks source link

Unsure what the different methods for decoding/encoding are for (Addx, DecodeX, X) #85

Closed jogramming closed 5 years ago

jogramming commented 5 years ago

There's 3 variations of all the methods, they all have the same comments but reading the source they seem to do different things?

example:

Decoder.DecodeString Decoder.AddString Decoder.String

Which ones should i use?

francoispqt commented 5 years ago

Hi, AddString and String are the same, they are meant to be used within an UnmarshalJSON[Object|Array] method.

DecodeString is meant to be used at a root decoding method. Example:

var jsonString = strings.NewReader(`"foobar"`)
var str string
var dec = NewDecoder(jsonString)
var err = dec.DecodeString(&str)