Easyjson用于序列化JSON数据,采用Go语言编写,而不是通过使用反射生成编组代码。一个库的目的之一是使所生成的代码足够简单,使得它可以容易地优化或固定。另一个目标是为用户提供不可定制的“encoding/json”,如产生snake_case名称或启用默认“omitempty“生成代码。
用法:
go get github.com/mailru/easyjson/... easyjson -all <file>.go
这将利用编组/解组方法结构生成_easyjson.go。
限制:
The library is at an early stage, there are likely to be some bugs and some features of ‘encoding/json’ may not be supported. Please report such cases, so that they may be fixed sooner.
Unsafe package is used by the code. While a non-unsafe version of easyjson can be made in the future, using unsafe package simplifies a lot of code by allowing to use ‘switch’ for filling out structs and working around limitations of standard functions like ‘strconv.ParseInt’.
Floats are currently formatted with default precision for ‘strconv’ package. It is obvious that it is not always the correct way to handle it, but there aren’t enough use-cases for floats at hand to do anything better.
During parsing, parts of JSON that are skipped over are not syntactically validated more than required to skip matching parentheses.
No true streaming support for encoding/decoding. For many use-cases and protocols, data length is typically known on input and needs to be known before sending the data.
解析:
编组,one goroutine
编组,并发