Easyjson 快速JSON序列化开源项目

我要开发同款
诺克萨斯2016年03月16日
39阅读
所属分类Google Go、程序开发、其他开发相关
授权协议MIT

作品详情

Easyjson用于序列化JSON数据,采用Go语言编写,而不是通过使用反射生成编组代码。一个库的目的之一是使所生成的代码足够简单,使得它可以容易地优化或固定。另一个目标是为用户提供不可定制的“encoding/json”,如产生snake_case名称或启用默认“omitempty“生成代码。

用法:

go get github.com/mailru/easyjson/...easyjson -all <file>.go

这将利用编组/解组方法结构生成<file>_easyjson.go。

限制:

Thelibraryisatanearlystage,therearelikelytobesomebugsandsomefeaturesof'encoding/json'maynotbesupported.Pleasereportsuchcases,sothattheymaybefixedsooner.

Unsafepackageisusedbythecode.Whileanon-unsafeversionofeasyjsoncanbemadeinthefuture,usingunsafepackagesimplifiesalotofcodebyallowingtouse'switch'forfillingoutstructsandworkingaroundlimitationsofstandardfunctionslike'strconv.ParseInt'.

Floatsarecurrentlyformattedwithdefaultprecisionfor'strconv'package.Itisobviousthatitisnotalwaysthecorrectwaytohandleit,buttherearen'tenoughuse-casesforfloatsathandtodoanythingbetter.

Duringparsing,partsofJSONthatareskippedoverarenotsyntacticallyvalidatedmorethanrequiredtoskipmatchingparentheses.

Notruestreamingsupportforencoding/decoding.Formanyuse-casesandprotocols,datalengthistypicallyknownoninputandneedstobeknownbeforesendingthedata.

解析:

libjsonsizeMB/sallocs/opB/opstandardregular2221810229standardsmall9.714720-------------------------------------------easyjsonregular1251289794easyjsonsmall673128-------------------------------------------ffjsonregular661419985ffjsonsmall17.610488-------------------------------------------codecregular5543419299codecsmall297336-------------------------------------------ujsonregular103N/AN/A

编组,onegoroutine

libjsonsizeMB/sallocs/opB/opstandardregular75923256standardsmall323328standardlarge80171.2M---------------------------------------------easyjsonregular213910260easyjson*regular2638742easyjsonsmall1251128easyjsonlarge21233490keasyjson*large262252879---------------------------------------------ffjsonregular12215321340ffjson**regular1461524897ffjsonsmall365384ffjson**small644128ffjsonlarge1347317818kffjson**large1257320827k---------------------------------------------codecregular801733601codec***regular10891153codecsmall423304codec***small56148codeclarge734832.5Mcodec***large10345166007---------------------------------------------ujsonregular92N/AN/A

编组,并发

libjsonsizeMB/sallocs/opB/opstandardregular252923257standardsmall1243328standardlarge289171.2M----------------------------------------------easyjsonregular792910597easyjson*regular17488779easyjsonsmall3331128easyjsonlarge71836548keasyjson*large2134254957---------------------------------------------ffjsonregular30115321629ffjson**regular7071525148ffjsonsmall625384ffjson**small2824128ffjsonlarge43873301.0Mffjson**large1317319820k---------------------------------------------codecregular1831733603codec***regular67191157codecsmall1473304codec***small299148codeclarge1904832.5Mcodec***large75245177574

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论