Slide 5
Slide 5 text
v2のUnmarshal: 4つの改善ポイント
5
func Unmarshal(in []byte, out any, opts ...Options) (err error) {
dec := export.GetBufferedDecoder(in, opts...)
defer export.PutBufferedDecoder(dec)
xd := export.Decoder(dec)
err = unmarshalDecode(dec, out, &xd.Struct, true)
return err
}
コード 改善ポイント
export オブジェクト パッケージ分離
err エラーの原因特定
Get/PutBufferedDecoder オブジェクトの再利用(sync.Pool)
Decoder 構造体 効率的なバッファ管理
src/encoding/json/v2/arshal.go