欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Golang高性能json包:easyjson

簡介

easyjson是什么呢? 根據(jù)官網(wǎng)介紹,easyjson是提供高效快速且易用的結(jié)構(gòu)體structs<-->json轉(zhuǎn)換包。easyjson并沒有使用反射方式實現(xiàn),所以性能比其他的json包該4-5倍,比golang 自帶的json包快2-3倍。 easyjson目標是維持生成去代碼簡單,以致于它可以輕松地進行優(yōu)化或固定。

成都創(chuàng)新互聯(lián)公司從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都做網(wǎng)站、網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元伍家崗做網(wǎng)站,已為上家服務(wù),為伍家崗各地企業(yè)和個人服務(wù),聯(lián)系電話:18982081108

安裝

go get -u github.com/mailru/easyjson/go install  github.com/mailru/easyjson/easyjsonorgo build -o easyjson github.com/mailru/easyjson/easyjson

驗證是否安裝成功。

$ easyjson
Usage of D:\Code\go\bin\easyjson.exe:
  -all        generate marshaler/unmarshalers for all structs in a file
  -build_tags string        build tags to add to generated file
  -leave_temps        do not delete temporary files
  -lower_camel_case        use lowerCamelCase names instead of CamelCase by default
  -no_std_marshalers        don't generate MarshalJSON/UnmarshalJSON funcs
  -noformat        do not run 'gofmt -w' on output file
  -omit_empty        omit empty fields by default

   string
        specify the filename of the output
  -pkg        process the whole package instead of just the given file
  -snake_case        use snake_case names instead of CamelCase by default
  -stubs        only generate stubs for marshaler/unmarshaler funcs

其中有幾個選項需要注意:

-lower_camel_case:將結(jié)構(gòu)體字段field首字母改為小寫。如Name=>name。  
-build_tags string:將指定的string生成到生成的go文件頭部。  
-no_std_marshalers:不為結(jié)構(gòu)體生成MarshalJSON/UnmarshalJSON函數(shù)。  
-omit_empty:沒有賦值的field可以不生成到j(luò)son,否則field為該字段類型的默認值。-output_filename:定義生成的文件名稱。-pkg:對包內(nèi)指定有`//easyjson:json`結(jié)構(gòu)體生成對應(yīng)的easyjson配置。-snke_case:可以下劃線的field如`Name_Student`改為`name_student`。

使用

記得在需要使用easyjson的結(jié)構(gòu)體上加上//easyjson:json。 如下:

//easyjson:jsontype School struct {    Name string        `json:"name"`
    Addr string        `json:"addr"`}//easyjson:jsontype Student struct {
    Id       int       `json:"id"`
    Name     string    `json:"s_name"`
    School   School    `json:"s_chool"`
    Birthday time.Time `json:"birthday"`}

在結(jié)構(gòu)體包下執(zhí)行

easyjson  -all student.go

此時在該目錄下出現(xiàn)一個新的文件。

// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.package easyjsonimport (
    json "encoding/json"
    easyjson "github.com/mailru/easyjson"
    jlexer "github.com/mailru/easyjson/jlexer"
    jwriter "github.com/mailru/easyjson/jwriter")// suppress unused package warningvar (
    _ *json.RawMessage
    _ *jlexer.Lexer
    _ *jwriter.Writer
    _ easyjson.Marshaler)func easyjsonB83d7b77DecodeStudygoEasyjson(in *jlexer.Lexer, out *Student) {
    isTopLevel := in.IsStart()    if in.IsNull() {        if isTopLevel {            in.Consumed()
        }        in.Skip()        return
    }    in.Delim('{')    for !in.IsDelim('}') {
        key := in.UnsafeString()        in.WantColon()        if in.IsNull() {            in.Skip()            in.WantComma()            continue
        }        switch key {        case "id":            out.Id = int(in.Int())        case "s_name":            out.Name = string(in.String())        case "s_chool":
            easyjsonB83d7b77DecodeStudygoEasyjson1(in, &out.School)        case "birthday":            if data := in.Raw(); in.Ok() {                in.AddError((out.Birthday).UnmarshalJSON(data))
            }        default:            in.SkipRecursive()
        }        in.WantComma()
    }    in.Delim('}')    if isTopLevel {        in.Consumed()
    }
}func easyjsonB83d7b77EncodeStudygoEasyjson(out *jwriter.Writer, in Student) {    out.RawByte('{')
    first := true
    _ = first    if !first {        out.RawByte(',')
    }
    first = false
    out.RawString("\"id\":")    out.Int(int(in.Id))    if !first {        out.RawByte(',')
    }
    first = false
    out.RawString("\"s_name\":")    out.String(string(in.Name))    if !first {        out.RawByte(',')
    }
    first = false
    out.RawString("\"s_chool\":")
    easyjsonB83d7b77EncodeStudygoEasyjson1(out, in.School)    if !first {        out.RawByte(',')
    }
    first = false
    out.RawString("\"birthday\":")    out.Raw((in.Birthday).MarshalJSON())    out.RawByte('}')
}// MarshalJSON supports json.Marshaler interfacefunc (v Student) MarshalJSON() ([]byte, error) {
    w := jwriter.Writer{}
    easyjsonB83d7b77EncodeStudygoEasyjson(&w, v)    return w.Buffer.BuildBytes(), w.Error
}// MarshalEasyJSON supports easyjson.Marshaler interfacefunc (v Student) MarshalEasyJSON(w *jwriter.Writer) {
    easyjsonB83d7b77EncodeStudygoEasyjson(w, v)
}// UnmarshalJSON supports json.Unmarshaler interfacefunc (v *Student) UnmarshalJSON(data []byte) error {
    r := jlexer.Lexer{Data: data}
    easyjsonB83d7b77DecodeStudygoEasyjson(&r, v)    return r.Error()
}// UnmarshalEasyJSON supports easyjson.Unmarshaler interfacefunc (v *Student) UnmarshalEasyJSON(l *jlexer.Lexer) {
    easyjsonB83d7b77DecodeStudygoEasyjson(l, v)
}func easyjsonB83d7b77DecodeStudygoEasyjson1(in *jlexer.Lexer, out *School) {
    isTopLevel := in.IsStart()    if in.IsNull() {        if isTopLevel {            in.Consumed()
        }        in.Skip()        return
    }    in.Delim('{')    for !in.IsDelim('}') {
        key := in.UnsafeString()        in.WantColon()        if in.IsNull() {            in.Skip()            in.WantComma()            continue
        }        switch key {        case "name":            out.Name = string(in.String())        case "addr":            out.Addr = string(in.String())        default:            in.SkipRecursive()
        }        in.WantComma()
    }    in.Delim('}')    if isTopLevel {        in.Consumed()
    }
}func easyjsonB83d7b77EncodeStudygoEasyjson1(out *jwriter.Writer, in School) {    out.RawByte('{')
    first := true
    _ = first    if !first {        out.RawByte(',')
    }
    first = false
    out.RawString("\"name\":")    out.String(string(in.Name))    if !first {        out.RawByte(',')
    }
    first = false
    out.RawString("\"addr\":")    out.String(string(in.Addr))    out.RawByte('}')
}

現(xiàn)在可以寫一個測試類啦。

package mainimport (    "studygo/easyjson"
    "time"
    "fmt")func main(){
    s:=easyjson.Student{
        Id: 11,
        Name:"qq",
        School:easyjson.School{
            Name:"CUMT",
            Addr:"xz",
        },
        Birthday:time.Now(),
    }
    bt,err:=s.MarshalJSON()
    fmt.Println(string(bt),err)
    json:=`{"id":11,"s_name":"qq","s_chool":{"name":"CUMT","addr":"xz"},"birthday":"2017-08-04T20:58:07.9894603+08:00"}`
    ss:=easyjson.Student{}
    ss.UnmarshalJSON([]byte(json))
    fmt.Println(ss)
}

運行結(jié)果:

{"id":11,"s_name":"qq","s_chool":{"name":"CUMT","addr":"xz"},"birthday":"2017-08-04T20:58:07.9894603+08:00"} <nil>
{121  {CwwwwwwwUMT xzwwwww} 2017-08-04 20:52:03.4066002 +0800 CST}

新聞標題:Golang高性能json包:easyjson
標題鏈接:http://www.aaarwkj.com/article32/pcdgsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、服務(wù)器托管、手機網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作小程序開發(fā)、域名注冊

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
人妻有码系列中文字幕专区| 最新日韩欧美一区二区| 日韩电影一区二区在线观看中文字幕 | 午夜免费视频观看在线| 日韩精品熟妻人女亚洲一区| 四虎免费在线视频观看| 熟女亚洲一区精品久久| 国产精品18禁一区二区三区| 久久免费欧美日韩亚洲| 国产福利在线观看网站| 国产不卡高清视频在线| 日韩精品在线观看一| 粉嫩美女精品一区二区| 久久精品国产av一一区| 欧美日韩国产一区在线| 一区二区三区福利视频在线观看 | 日本免费一区二区三区的电影啊| 午夜视频在线观看免费高清国产| 欧美精品欧美精品一区二区 | 亚洲女同另类在线播放视频| 看夫妻性生活免费视频| 欧美日韩精品久久影院| 色综合亚洲一区二区小说| 久久精品国产亚洲av麻豆尤物| 久久精品国产亚洲av一| 亚洲另类欧美日韩中文字幕| 麻豆视频91免费观看| 欧美午夜国产在线观看| 日韩在线视频不卡播放| 永久免费看黄在线观看| 国产成人性生交大片免费| av国产剧情在线观看| 日韩丰满少妇在线观看| 国产亚洲欧美精品久久久久| 日韩人妻精品中文字幕专区不卡| 在线观看中文字幕有码| 国产亚洲欧美日韩网站| 人人看男人的天堂东京| 日韩欧美日日夜夜精品| 男人喜欢看的免费视频| 人妻免费视频中文字幕|