├── .github └── workflows │ └── semgrep.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── Make.tests ├── Makefile ├── README.md └── src ├── .gitignore ├── capnp ├── country.capnp ├── go.capnp ├── log.capnp └── lua.capnp ├── gogopb ├── ip.go └── log.proto ├── gogopb_both ├── ip.go └── log.proto ├── gogopb_nullable ├── ip.go └── log.proto ├── gogopb_unsafe ├── ip.go └── log.proto ├── goser ├── bench_test.go └── util_test.go └── pb └── log.proto /.github/workflows/semgrep.yml: -------------------------------------------------------------------------------- 1 | 2 | on: 3 | pull_request: {} 4 | workflow_dispatch: {} 5 | push: 6 | branches: 7 | - main 8 | - master 9 | name: Semgrep config 10 | jobs: 11 | semgrep: 12 | name: semgrep/ci 13 | runs-on: ubuntu-20.04 14 | env: 15 | SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} 16 | SEMGREP_URL: https://cloudflare.semgrep.dev 17 | SEMGREP_APP_URL: https://cloudflare.semgrep.dev 18 | SEMGREP_VERSION_CHECK_URL: https://cloudflare.semgrep.dev/api/check-version 19 | container: 20 | image: returntocorp/semgrep 21 | steps: 22 | - uses: actions/checkout@v3 23 | - run: semgrep ci 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | lib/ 3 | include/ 4 | pkg/ 5 | capnproto-*/ 6 | protobuf-*/ 7 | gopath/ 8 | *.test 9 | *.capnp.go 10 | *.pb.go 11 | *pb_test.go 12 | cpu.prof 13 | cpu.svg 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | before_install: 4 | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 5 | - sudo apt-get update -qq 6 | - sudo apt-get install -y g++-4.9 7 | 8 | env: 9 | global: 10 | - CXX=g++-4.9 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, CloudFlare, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the author nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /Make.tests: -------------------------------------------------------------------------------- 1 | DIRS=$(subst $(space),$(newline),$(shell cd src && go list ./...)) 2 | 3 | TEST=$(subst $(space),$(newline),$(shell cd src && go list -f '{{if or .TestGoFiles .XTestGoFiles}}{{.Dir}}{{end}}' ./...)) 4 | 5 | NOTEST=$(filter-out $(TEST),$(DIRS)) 6 | 7 | test-compile: $(addsuffix .test-compile, $(TEST)) 8 | 9 | %.test-compile: 10 | cd $* && go test -compiler=$(COMPILER) -p 1 -v -c . 11 | 12 | notest: 13 | @echo $(NOTEST) | xargs -n 1 echo 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH := $(PWD):$(PWD)/gopath 2 | export PATH := $(PWD)/gopath/bin:$(PATH) 3 | export GOMAXPROCS := 1 4 | 5 | GOCMD := go 6 | CAPNP_VERSION := 0.5.2 7 | CAPNP_NAME := capnproto-c++-$(CAPNP_VERSION) 8 | CAPNP_CMD := $(CAPNP_NAME)/capnp 9 | PROTOC_VERSION := 2.6.1 10 | PROTOC_NAME := protobuf-$(PROTOC_VERSION) 11 | PROTOC_CMD := $(PROTOC_NAME)/src/protoc 12 | 13 | .PHONY: all 14 | all: get capnp proto 15 | go test -c goser 16 | ./goser.test -test.benchtime=10s -test.cpuprofile=cpu.prof -test.run=XXX -test.bench=. -test.benchmem 17 | go tool pprof --svg goser.test cpu.prof > cpu.svg 18 | 19 | .PHONY: proto 20 | proto: $(PROTOC_CMD) 21 | go version 22 | go install -v github.com/golang/protobuf/protoc-gen-go 23 | go install -v github.com/gogo/protobuf/protoc-gen-gogo 24 | cd src && ../$(PROTOC_CMD) --go_out=. pb/log.proto 25 | cd src && ../$(PROTOC_CMD) -I$(PWD)/gopath/src -I$(PWD)/gopath/src/github.com/gogo/protobuf/protobuf -I. --gogo_out=. gogopb/log.proto 26 | cd src && ../$(PROTOC_CMD) -I$(PWD)/gopath/src -I$(PWD)/gopath/src/github.com/gogo/protobuf/protobuf -I. --gogo_out=. gogopb_nullable/log.proto 27 | cd src && ../$(PROTOC_CMD) -I$(PWD)/gopath/src -I$(PWD)/gopath/src/github.com/gogo/protobuf/protobuf -I. --gogo_out=. gogopb_unsafe/log.proto 28 | cd src && ../$(PROTOC_CMD) -I$(PWD)/gopath/src -I$(PWD)/gopath/src/github.com/gogo/protobuf/protobuf -I. --gogo_out=. gogopb_both/log.proto 29 | 30 | $(PROTOC_CMD): 31 | test -d $(PROTOC_NAME) || curl -s -L https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/$(PROTOC_NAME).tar.bz2 | tar jx 32 | cd $(PROTOC_NAME) && \ 33 | ./configure && \ 34 | make -j3 35 | 36 | .PHONY: capnp 37 | capnp: $(CAPNP_CMD) 38 | go version 39 | go install -v github.com/glycerine/go-capnproto/capnpc-go 40 | $(CAPNP_CMD) compile --verbose -ogo $(PWD)/src/capnp/log.capnp $(PWD)/src/capnp/country.capnp 41 | 42 | $(CAPNP_CMD): 43 | test -d $(CAPNP_NAME) || curl -s -L https://capnproto.org/$(CAPNP_NAME).tar.gz | tar zx 44 | cd $(CAPNP_NAME) && \ 45 | ./configure && \ 46 | make -j3 47 | 48 | .PHONY: get 49 | get: 50 | GOPATH=$(PWD)/gopath go get -u -d github.com/golang/protobuf/proto 51 | GOPATH=$(PWD)/gopath go get -u -d github.com/gogo/protobuf/proto 52 | GOPATH=$(PWD)/gopath go get -u -d github.com/gogo/harmonytests 53 | GOPATH=$(PWD)/gopath go get -u -d github.com/glycerine/go-capnproto 54 | GOPATH=$(PWD)/gopath go get -u -d github.com/kaos/capnp_test || true 55 | GOPATH=$(PWD)/gopath go get golang.org/x/tools/cmd/benchcmp 56 | 57 | .PHONY: gofmt 58 | gofmt: 59 | $(GOCMD) fmt ./... 60 | 61 | .PHONY: test 62 | test: 63 | go test -v ./... 64 | 65 | .PHONY: test-compile 66 | test-compile: all 67 | @$(MAKE) --no-print-directory -f Make.tests $@ 68 | 69 | .PHONY: clean-pkg 70 | clean-pkg: 71 | $(RM) -rf pkg gopath/pkg 72 | 73 | .PHONY: clean 74 | clean: clean-pkg 75 | $(RM) -rf bin gopath/bin 76 | 77 | DEFAULT_GOAL := all 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Go Serialization benchmarks 2 | =========================== 3 | 4 | Just type: make 5 | 6 | Good luck! 7 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | code.google.com/ 2 | -------------------------------------------------------------------------------- /src/capnp/country.capnp: -------------------------------------------------------------------------------- 1 | @0x91b19db84879627f; 2 | 3 | using Go = import "go.capnp"; 4 | $Go.package("capnp"); 5 | $Go.import("capnp"); 6 | 7 | enum Country { 8 | unknown @0; 9 | # Anonymous Proxy 10 | a1 @1; 11 | # Satellite Provider 12 | a2 @2; 13 | # Other Country 14 | o1 @3; 15 | # Andorra 16 | ad @4; 17 | # United Arab Emirates 18 | ae @5; 19 | # Afghanistan 20 | af @6; 21 | # Antigua and Barbuda 22 | ag @7; 23 | # Anguilla 24 | ai @8; 25 | # Albania 26 | al @9; 27 | # Armenia 28 | am @10; 29 | # Angola 30 | ao @11; 31 | # Asia/Pacific Region 32 | ap @12; 33 | # Antarctica 34 | aq @13; 35 | # Argentina 36 | ar @14; 37 | # American Samoa 38 | as @15; 39 | # Austria 40 | at @16; 41 | # Australia 42 | au @17; 43 | # Aruba 44 | aw @18; 45 | # Aland Islands 46 | ax @19; 47 | # Azerbaijan 48 | az @20; 49 | # Bosnia and Herzegovina 50 | ba @21; 51 | # Barbados 52 | bb @22; 53 | # Bangladesh 54 | bd @23; 55 | # Belgium 56 | be @24; 57 | # Burkina Faso 58 | bf @25; 59 | # Bulgaria 60 | bg @26; 61 | # Bahrain 62 | bh @27; 63 | # Burundi 64 | bi @28; 65 | # Benin 66 | bj @29; 67 | # Saint Bartelemey 68 | bl @30; 69 | # Bermuda 70 | bm @31; 71 | # Brunei Darussalam 72 | bn @32; 73 | # Bolivia 74 | bo @33; 75 | # Bonaire, Saint Eustatius and Saba 76 | bq @34; 77 | # Brazil 78 | br @35; 79 | # Bahamas 80 | bs @36; 81 | # Bhutan 82 | bt @37; 83 | # Bouvet Island 84 | bv @38; 85 | # Botswana 86 | bw @39; 87 | # Belarus 88 | by @40; 89 | # Belize 90 | bz @41; 91 | # Canada 92 | ca @42; 93 | # Cocos (Keeling) Islands 94 | cc @43; 95 | # Congo, The Democratic Republic of the 96 | cd @44; 97 | # Central African Republic 98 | cf @45; 99 | # Congo 100 | cg @46; 101 | # Switzerland 102 | ch @47; 103 | # Cote d'Ivoire 104 | ci @48; 105 | # Cook Islands 106 | ck @49; 107 | # Chile 108 | cl @50; 109 | # Cameroon 110 | cm @51; 111 | # China 112 | cn @52; 113 | # Colombia 114 | co @53; 115 | # Costa Rica 116 | cr @54; 117 | # Cuba 118 | cu @55; 119 | # Cape Verde 120 | cv @56; 121 | # Curacao 122 | cw @57; 123 | # Christmas Island 124 | cx @58; 125 | # Cyprus 126 | cy @59; 127 | # Czech Republic 128 | cz @60; 129 | # Germany 130 | de @61; 131 | # Djibouti 132 | dj @62; 133 | # Denmark 134 | dk @63; 135 | # Dominica 136 | dm @64; 137 | # Dominican Republic 138 | do @65; 139 | # Algeria 140 | dz @66; 141 | # Ecuador 142 | ec @67; 143 | # Estonia 144 | ee @68; 145 | # Egypt 146 | eg @69; 147 | # Western Sahara 148 | eh @70; 149 | # Eritrea 150 | er @71; 151 | # Spain 152 | es @72; 153 | # Ethiopia 154 | et @73; 155 | # Europe 156 | eu @74; 157 | # Finland 158 | fi @75; 159 | # Fiji 160 | fj @76; 161 | # Falkland Islands (Malvinas) 162 | fk @77; 163 | # Micronesia, Federated States of 164 | fm @78; 165 | # Faroe Islands 166 | fo @79; 167 | # France 168 | fr @80; 169 | # Gabon 170 | ga @81; 171 | # United Kingdom 172 | gb @82; 173 | # Grenada 174 | gd @83; 175 | # Georgia 176 | ge @84; 177 | # French Guiana 178 | gf @85; 179 | # Guernsey 180 | gg @86; 181 | # Ghana 182 | gh @87; 183 | # Gibraltar 184 | gi @88; 185 | # Greenland 186 | gl @89; 187 | # Gambia 188 | gm @90; 189 | # Guinea 190 | gn @91; 191 | # Guadeloupe 192 | gp @92; 193 | # Equatorial Guinea 194 | gq @93; 195 | # Greece 196 | gr @94; 197 | # South Georgia and the South Sandwich Islands 198 | gs @95; 199 | # Guatemala 200 | gt @96; 201 | # Guam 202 | gu @97; 203 | # Guinea-Bissau 204 | gw @98; 205 | # Guyana 206 | gy @99; 207 | # Hong Kong 208 | hk @100; 209 | # Heard Island and McDonald Islands 210 | hm @101; 211 | # Honduras 212 | hn @102; 213 | # Croatia 214 | hr @103; 215 | # Haiti 216 | ht @104; 217 | # Hungary 218 | hu @105; 219 | # Indonesia 220 | id @106; 221 | # Ireland 222 | ie @107; 223 | # Israel 224 | il @108; 225 | # Isle of Man 226 | im @109; 227 | # India 228 | in @110; 229 | # British Indian Ocean Territory 230 | io @111; 231 | # Iraq 232 | iq @112; 233 | # Iran, Islamic Republic of 234 | ir @113; 235 | # Iceland 236 | is @114; 237 | # Italy 238 | it @115; 239 | # Jersey 240 | je @116; 241 | # Jamaica 242 | jm @117; 243 | # Jordan 244 | jo @118; 245 | # Japan 246 | jp @119; 247 | # Kenya 248 | ke @120; 249 | # Kyrgyzstan 250 | kg @121; 251 | # Cambodia 252 | kh @122; 253 | # Kiribati 254 | ki @123; 255 | # Comoros 256 | km @124; 257 | # Saint Kitts and Nevis 258 | kn @125; 259 | # Korea, Democratic People's Republic of 260 | kp @126; 261 | # Korea, Republic of 262 | kr @127; 263 | # Kuwait 264 | kw @128; 265 | # Cayman Islands 266 | ky @129; 267 | # Kazakhstan 268 | kz @130; 269 | # Lao People's Democratic Republic 270 | la @131; 271 | # Lebanon 272 | lb @132; 273 | # Saint Lucia 274 | lc @133; 275 | # Liechtenstein 276 | li @134; 277 | # Sri Lanka 278 | lk @135; 279 | # Liberia 280 | lr @136; 281 | # Lesotho 282 | ls @137; 283 | # Lithuania 284 | lt @138; 285 | # Luxembourg 286 | lu @139; 287 | # Latvia 288 | lv @140; 289 | # Libyan Arab Jamahiriya 290 | ly @141; 291 | # Morocco 292 | ma @142; 293 | # Monaco 294 | mc @143; 295 | # Moldova, Republic of 296 | md @144; 297 | # Montenegro 298 | me @145; 299 | # Saint Martin 300 | mf @146; 301 | # Madagascar 302 | mg @147; 303 | # Marshall Islands 304 | mh @148; 305 | # Macedonia 306 | mk @149; 307 | # Mali 308 | ml @150; 309 | # Myanmar 310 | mm @151; 311 | # Mongolia 312 | mn @152; 313 | # Macao 314 | mo @153; 315 | # Northern Mariana Islands 316 | mp @154; 317 | # Martinique 318 | mq @155; 319 | # Mauritania 320 | mr @156; 321 | # Montserrat 322 | ms @157; 323 | # Malta 324 | mt @158; 325 | # Mauritius 326 | mu @159; 327 | # Maldives 328 | mv @160; 329 | # Malawi 330 | mw @161; 331 | # Mexico 332 | mx @162; 333 | # Malaysia 334 | my @163; 335 | # Mozambique 336 | mz @164; 337 | # Namibia 338 | na @165; 339 | # New Caledonia 340 | nc @166; 341 | # Niger 342 | ne @167; 343 | # Norfolk Island 344 | nf @168; 345 | # Nigeria 346 | ng @169; 347 | # Nicaragua 348 | ni @170; 349 | # Netherlands 350 | nl @171; 351 | # Norway 352 | no @172; 353 | # Nepal 354 | np @173; 355 | # Nauru 356 | nr @174; 357 | # Niue 358 | nu @175; 359 | # New Zealand 360 | nz @176; 361 | # Oman 362 | om @177; 363 | # Panama 364 | pa @178; 365 | # Peru 366 | pe @179; 367 | # French Polynesia 368 | pf @180; 369 | # Papua New Guinea 370 | pg @181; 371 | # Philippines 372 | ph @182; 373 | # Pakistan 374 | pk @183; 375 | # Poland 376 | pl @184; 377 | # Saint Pierre and Miquelon 378 | pm @185; 379 | # Pitcairn 380 | pn @186; 381 | # Puerto Rico 382 | pr @187; 383 | # Palestinian Territory 384 | ps @188; 385 | # Portugal 386 | pt @189; 387 | # Palau 388 | pw @190; 389 | # Paraguay 390 | py @191; 391 | # Qatar 392 | qa @192; 393 | # Reunion 394 | re @193; 395 | # Romania 396 | ro @194; 397 | # Serbia 398 | rs @195; 399 | # Russian Federation 400 | ru @196; 401 | # Rwanda 402 | rw @197; 403 | # Saudi Arabia 404 | sa @198; 405 | # Solomon Islands 406 | sb @199; 407 | # Seychelles 408 | sc @200; 409 | # Sudan 410 | sd @201; 411 | # Sweden 412 | se @202; 413 | # Singapore 414 | sg @203; 415 | # Saint Helena 416 | sh @204; 417 | # Slovenia 418 | si @205; 419 | # Svalbard and Jan Mayen 420 | sj @206; 421 | # Slovakia 422 | sk @207; 423 | # Sierra Leone 424 | sl @208; 425 | # San Marino 426 | sm @209; 427 | # Senegal 428 | sn @210; 429 | # Somalia 430 | so @211; 431 | # Suriname 432 | sr @212; 433 | # South Sudan 434 | ss @213; 435 | # Sao Tome and Principe 436 | st @214; 437 | # El Salvador 438 | sv @215; 439 | # Sint Maarten 440 | sx @216; 441 | # Syrian Arab Republic 442 | sy @217; 443 | # Swaziland 444 | sz @218; 445 | # Turks and Caicos Islands 446 | tc @219; 447 | # Chad 448 | td @220; 449 | # French Southern Territories 450 | tf @221; 451 | # Togo 452 | tg @222; 453 | # Thailand 454 | th @223; 455 | # Tajikistan 456 | tj @224; 457 | # Tokelau 458 | tk @225; 459 | # Timor-Leste 460 | tl @226; 461 | # Turkmenistan 462 | tm @227; 463 | # Tunisia 464 | tn @228; 465 | # Tonga 466 | to @229; 467 | # Turkey 468 | tr @230; 469 | # Trinidad and Tobago 470 | tt @231; 471 | # Tuvalu 472 | tv @232; 473 | # Taiwan 474 | tw @233; 475 | # Tanzania, United Republic of 476 | tz @234; 477 | # Ukraine 478 | ua @235; 479 | # Uganda 480 | ug @236; 481 | # United States Minor Outlying Islands 482 | um @237; 483 | # United States 484 | us @238; 485 | # Uruguay 486 | uy @239; 487 | # Uzbekistan 488 | uz @240; 489 | # Holy See (Vatican City State) 490 | va @241; 491 | # Saint Vincent and the Grenadines 492 | vc @242; 493 | # Venezuela 494 | ve @243; 495 | # Virgin Islands, British 496 | vg @244; 497 | # Virgin Islands, U.S. 498 | vi @245; 499 | # Vietnam 500 | vn @246; 501 | # Vanuatu 502 | vu @247; 503 | # Wallis and Futuna 504 | wf @248; 505 | # Samoa 506 | ws @249; 507 | # Other Countries 508 | xx @250; 509 | # Yemen 510 | ye @251; 511 | # Mayotte 512 | yt @252; 513 | # South Africa 514 | za @253; 515 | # Zambia 516 | zm @254; 517 | # Zimbabwe 518 | zw @255; 519 | max @256; 520 | } 521 | -------------------------------------------------------------------------------- /src/capnp/go.capnp: -------------------------------------------------------------------------------- 1 | @0xd12a1c51fedd6c88; 2 | annotation package(file) :Text; 3 | annotation import(file) :Text; 4 | annotation tag(enumerant) : Text; 5 | annotation notag(enumerant) : Void; 6 | annotation jsonfmt(field) : Jsonfmts; 7 | struct Jsonfmts { 8 | pkg @0 : Text; 9 | fmt @1 : Text; 10 | } 11 | $package("capn"); 12 | -------------------------------------------------------------------------------- /src/capnp/log.capnp: -------------------------------------------------------------------------------- 1 | using Go = import "go.capnp"; 2 | using Lua = import "lua.capnp"; 3 | 4 | $Go.package("capnp"); 5 | $Go.import("capnp"); 6 | 7 | @0xe6860092ff3f0a59; 8 | 9 | using import "country.capnp".Country; 10 | 11 | struct HTTP { 12 | protocol @0 :Protocol; 13 | enum Protocol { 14 | unknown @0; 15 | http10 @1; 16 | http11 @2; 17 | max @3; 18 | } 19 | 20 | status @1 :UInt16; 21 | 22 | hostStatus @2 :UInt16; 23 | 24 | upStatus @3 :UInt16; 25 | 26 | method @4 :Method; 27 | enum Method { 28 | unknown @0; 29 | get @1; 30 | post @2; 31 | delete @3; 32 | put @4; 33 | head @5; 34 | purge @6; 35 | options @7; 36 | propfind @8; 37 | mkcol @9; 38 | patch @10; 39 | max @11; 40 | } 41 | 42 | contentType @5 :Text; 43 | userAgent @6 :Text; 44 | referer @7 :Text; 45 | requestURI @8 :Text; 46 | } 47 | 48 | enum CacheStatus { 49 | unknown @0; 50 | miss @1; 51 | expired @2; 52 | hit @3; 53 | max @4; 54 | } 55 | 56 | struct Origin { 57 | ip @0 :Data $Go.jsonfmt(pkg="net", fmt="net.IP(s).String()"); 58 | port @1 :UInt16; 59 | hostname @2 :Text; 60 | protocol @3 :Protocol; 61 | enum Protocol $Lua.naming("lower_underscore") { 62 | unknown @0; 63 | http @1; 64 | https @2; 65 | max @3; 66 | } 67 | } 68 | 69 | enum ZonePlan { 70 | unknown @0 $Go.tag(""); 71 | free @1 $Go.tag("Free"); 72 | pro @2 $Go.tag("Pro"); 73 | biz @3 $Go.tag("Business"); 74 | ent @4 $Go.tag("Enterprise"); 75 | max @5; 76 | } 77 | 78 | struct Log { 79 | timestamp @0 :Int64; 80 | zoneId @1 :UInt32; 81 | zonePlan @2 :ZonePlan; 82 | http @3 :HTTP; 83 | origin @4 :Origin; 84 | country @5 :Country; 85 | cacheStatus @6 :CacheStatus; 86 | serverIp @7 :Data $Go.jsonfmt(pkg="net", fmt="net.IP(s).String()"); 87 | serverName @8 :Text; 88 | remoteIp @9 :Data $Go.jsonfmt(pkg="net", fmt="net.IP(s).String()"); 89 | bytesDlv @10 :UInt64; 90 | rayId @11 :Text; 91 | } 92 | -------------------------------------------------------------------------------- /src/capnp/lua.capnp: -------------------------------------------------------------------------------- 1 | @0xb1ce27b8f28b5e4d; 2 | 3 | annotation naming(enum, enumerant) : Text; 4 | -------------------------------------------------------------------------------- /src/gogopb/ip.go: -------------------------------------------------------------------------------- 1 | package gogopb 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "net" 7 | ) 8 | 9 | type IP net.IP 10 | 11 | func (this IP) Marshal() ([]byte, error) { 12 | return []byte(this), nil 13 | } 14 | 15 | func (this IP) MarshalTo(data []byte) (int, error) { 16 | n := copy(data, this) 17 | return n, nil 18 | } 19 | 20 | func (this *IP) Unmarshal(data []byte) error { 21 | if data == nil { 22 | *this = nil 23 | return nil 24 | } 25 | if len(*this) != len(data) { 26 | *this = IP(make([]byte, len(data))) 27 | } 28 | copy(*this, data) 29 | return nil 30 | } 31 | 32 | func (this IP) Size() int { 33 | return len(this) 34 | } 35 | 36 | type rander interface { 37 | Int63() int64 38 | } 39 | 40 | func NewPopulatedIP(r rander) *IP { 41 | ip := IP(net.IPv4(1, 2, 3, 4)) 42 | return &ip 43 | } 44 | 45 | func (this IP) Equal(other IP) bool { 46 | return bytes.Equal(this, other) 47 | } 48 | 49 | func (this IP) MarshalJSON() ([]byte, error) { 50 | return []byte("\"" + net.IP(this).String() + "\""), nil 51 | } 52 | 53 | func (this *IP) UnmarshalJSON(data []byte) error { 54 | if len(data) < 2 { 55 | return io.ErrShortBuffer 56 | } 57 | *this = IP(net.ParseIP(string(data[1 : len(data)-1]))) 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /src/gogopb/log.proto: -------------------------------------------------------------------------------- 1 | package proto; 2 | 3 | option go_package = "gogopb"; 4 | 5 | import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 6 | 7 | option (gogoproto.equal_all) = true; 8 | option (gogoproto.populate_all) = true; 9 | option (gogoproto.testgen_all) = true; 10 | option (gogoproto.benchgen_all) = true; 11 | 12 | message HTTP { 13 | enum Protocol { 14 | HTTP_PROTOCOL_UNKNOWN = 0; 15 | HTTP10 = 1; 16 | HTTP11 = 2; 17 | } 18 | optional Protocol protocol = 1; 19 | 20 | optional uint32 status = 2; 21 | optional uint32 hostStatus = 3; 22 | optional uint32 upStatus = 4; 23 | 24 | enum Method { 25 | METHOD_UNKNOWN = 0; 26 | GET = 1; 27 | POST = 2; 28 | DELETE = 3; 29 | PUT = 4; 30 | HEAD = 5; 31 | PURGE = 6; 32 | OPTIONS = 7; 33 | PROPFIND = 8; 34 | MKCOL = 9; 35 | PATCH = 10; 36 | } 37 | optional Method method = 5; 38 | 39 | optional string contentType = 6; 40 | optional string userAgent = 7; 41 | optional string referer = 8; 42 | optional string requestURI = 9; 43 | } 44 | 45 | enum CacheStatus { 46 | CACHESTATUS_UNKNOWN = 0; 47 | MISS = 1; 48 | EXPIRED = 2; 49 | HIT = 3; 50 | } 51 | 52 | message Origin { 53 | optional bytes ip = 1 [(gogoproto.customtype) = "IP"]; 54 | optional uint32 port = 2; 55 | optional string hostname = 3; 56 | enum Protocol { 57 | ORIGIN_PROTOCOL_UNKNOWN = 0; 58 | HTTP = 1; 59 | HTTPS = 2; 60 | } 61 | optional Protocol protocol = 4; 62 | } 63 | 64 | enum ZonePlan { 65 | ZONEPLAN_UNKNOWN = 0; 66 | FREE = 1; 67 | PRO = 2; 68 | BIZ = 3; 69 | ENT = 4; 70 | } 71 | 72 | message Log { 73 | optional sfixed64 timestamp = 1; 74 | optional uint32 zoneId = 2; 75 | optional ZonePlan zonePlan = 3; 76 | optional HTTP http = 4; 77 | optional Origin origin = 5; 78 | optional Country country = 6; 79 | optional CacheStatus cacheStatus = 7; 80 | optional bytes serverIp = 8 [(gogoproto.customtype) = "IP"]; 81 | optional string serverName = 9; 82 | optional bytes remoteIp = 10 [(gogoproto.customtype) = "IP"]; 83 | optional uint64 bytesDlv = 11; 84 | optional string rayId = 12; 85 | } 86 | 87 | enum Country { 88 | UNKNOWN = 0; 89 | A1 = 1; 90 | A2 = 2; 91 | O1 = 3; 92 | AD = 4; 93 | AE = 5; 94 | AF = 6; 95 | AG = 7; 96 | AI = 8; 97 | AL = 9; 98 | AM = 10; 99 | AO = 11; 100 | AP = 12; 101 | AQ = 13; 102 | AR = 14; 103 | AS = 15; 104 | AT = 16; 105 | AU = 17; 106 | AW = 18; 107 | AX = 19; 108 | AZ = 20; 109 | BA = 21; 110 | BB = 22; 111 | BD = 23; 112 | BE = 24; 113 | BF = 25; 114 | BG = 26; 115 | BH = 27; 116 | BI = 28; 117 | BJ = 29; 118 | BL = 30; 119 | BM = 31; 120 | BN = 32; 121 | BO = 33; 122 | BQ = 34; 123 | BR = 35; 124 | BS = 36; 125 | BT = 37; 126 | BV = 38; 127 | BW = 39; 128 | BY = 40; 129 | BZ = 41; 130 | CA = 42; 131 | CC = 43; 132 | CD = 44; 133 | CF = 45; 134 | CG = 46; 135 | CH = 47; 136 | CI = 48; 137 | CK = 49; 138 | CL = 50; 139 | CM = 51; 140 | CN = 52; 141 | CO = 53; 142 | CR = 54; 143 | CU = 55; 144 | CV = 56; 145 | CW = 57; 146 | CX = 58; 147 | CY = 59; 148 | CZ = 60; 149 | DE = 61; 150 | DJ = 62; 151 | DK = 63; 152 | DM = 64; 153 | DO = 65; 154 | DZ = 66; 155 | EC = 67; 156 | EE = 68; 157 | EG = 69; 158 | EH = 70; 159 | ER = 71; 160 | ES = 72; 161 | ET = 73; 162 | EU = 74; 163 | FI = 75; 164 | FJ = 76; 165 | FK = 77; 166 | FM = 78; 167 | FO = 79; 168 | FR = 80; 169 | GA = 81; 170 | GB = 82; 171 | GD = 83; 172 | GE = 84; 173 | GF = 85; 174 | GG = 86; 175 | GH = 87; 176 | GI = 88; 177 | GL = 89; 178 | GM = 90; 179 | GN = 91; 180 | GP = 92; 181 | GQ = 93; 182 | GR = 94; 183 | GS = 95; 184 | GT = 96; 185 | GU = 97; 186 | GW = 98; 187 | GY = 99; 188 | HK = 100; 189 | HM = 101; 190 | HN = 102; 191 | HR = 103; 192 | HT = 104; 193 | HU = 105; 194 | ID = 106; 195 | IE = 107; 196 | IL = 108; 197 | IM = 109; 198 | IN = 110; 199 | IO = 111; 200 | IQ = 112; 201 | IR = 113; 202 | IS = 114; 203 | IT = 115; 204 | JE = 116; 205 | JM = 117; 206 | JO = 118; 207 | JP = 119; 208 | KE = 120; 209 | KG = 121; 210 | KH = 122; 211 | KI = 123; 212 | KM = 124; 213 | KN = 125; 214 | KP = 126; 215 | KR = 127; 216 | KW = 128; 217 | KY = 129; 218 | KZ = 130; 219 | LA = 131; 220 | LB = 132; 221 | LC = 133; 222 | LI = 134; 223 | LK = 135; 224 | LR = 136; 225 | LS = 137; 226 | LT = 138; 227 | LU = 139; 228 | LV = 140; 229 | LY = 141; 230 | MA = 142; 231 | MC = 143; 232 | MD = 144; 233 | ME = 145; 234 | MF = 146; 235 | MG = 147; 236 | MH = 148; 237 | MK = 149; 238 | ML = 150; 239 | MM = 151; 240 | MN = 152; 241 | MO = 153; 242 | MP = 154; 243 | MQ = 155; 244 | MR = 156; 245 | MS = 157; 246 | MT = 158; 247 | MU = 159; 248 | MV = 160; 249 | MW = 161; 250 | MX = 162; 251 | MY = 163; 252 | MZ = 164; 253 | NA = 165; 254 | NC = 166; 255 | NE = 167; 256 | NF = 168; 257 | NG = 169; 258 | NI = 170; 259 | NL = 171; 260 | NO = 172; 261 | NP = 173; 262 | NR = 174; 263 | NU = 175; 264 | NZ = 176; 265 | OM = 177; 266 | PA = 178; 267 | PE = 179; 268 | PF = 180; 269 | PG = 181; 270 | PH = 182; 271 | PK = 183; 272 | PL = 184; 273 | PM = 185; 274 | PN = 186; 275 | PR = 187; 276 | PS = 188; 277 | PT = 189; 278 | PW = 190; 279 | PY = 191; 280 | QA = 192; 281 | RE = 193; 282 | RO = 194; 283 | RS = 195; 284 | RU = 196; 285 | RW = 197; 286 | SA = 198; 287 | SB = 199; 288 | SC = 200; 289 | SD = 201; 290 | SE = 202; 291 | SG = 203; 292 | SH = 204; 293 | SI = 205; 294 | SJ = 206; 295 | SK = 207; 296 | SL = 208; 297 | SM = 209; 298 | SN = 210; 299 | SO = 211; 300 | SR = 212; 301 | SS = 213; 302 | ST = 214; 303 | SV = 215; 304 | SX = 216; 305 | SY = 217; 306 | SZ = 218; 307 | TC = 219; 308 | TD = 220; 309 | TF = 221; 310 | TG = 222; 311 | TH = 223; 312 | TJ = 224; 313 | TK = 225; 314 | TL = 226; 315 | TM = 227; 316 | TN = 228; 317 | TO = 229; 318 | TR = 230; 319 | TT = 231; 320 | TV = 232; 321 | TW = 233; 322 | TZ = 234; 323 | UA = 235; 324 | UG = 236; 325 | UM = 237; 326 | US = 238; 327 | UY = 239; 328 | UZ = 240; 329 | VA = 241; 330 | VC = 242; 331 | VE = 243; 332 | VG = 244; 333 | VI = 245; 334 | VN = 246; 335 | VU = 247; 336 | WF = 248; 337 | WS = 249; 338 | XX = 250; 339 | YE = 251; 340 | YT = 252; 341 | ZA = 253; 342 | ZM = 254; 343 | ZW = 255; 344 | } 345 | -------------------------------------------------------------------------------- /src/gogopb_both/ip.go: -------------------------------------------------------------------------------- 1 | package gogopb 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "net" 7 | ) 8 | 9 | type IP net.IP 10 | 11 | func (this IP) Marshal() ([]byte, error) { 12 | return []byte(this), nil 13 | } 14 | 15 | func (this IP) MarshalTo(data []byte) (int, error) { 16 | n := copy(data, this) 17 | return n, nil 18 | } 19 | 20 | func (this *IP) Unmarshal(data []byte) error { 21 | if data == nil { 22 | *this = nil 23 | return nil 24 | } 25 | if len(*this) != len(data) { 26 | *this = IP(make([]byte, len(data))) 27 | } 28 | copy(*this, data) 29 | return nil 30 | } 31 | 32 | func (this IP) Size() int { 33 | return len(this) 34 | } 35 | 36 | type rander interface { 37 | Int63() int64 38 | } 39 | 40 | func NewPopulatedIP(r rander) *IP { 41 | ip := IP(net.IPv4(1, 2, 3, 4)) 42 | return &ip 43 | } 44 | 45 | func (this IP) Equal(other IP) bool { 46 | return bytes.Equal(this, other) 47 | } 48 | 49 | func (this IP) MarshalJSON() ([]byte, error) { 50 | return []byte("\"" + net.IP(this).String() + "\""), nil 51 | } 52 | 53 | func (this *IP) UnmarshalJSON(data []byte) error { 54 | if len(data) < 2 { 55 | return io.ErrShortBuffer 56 | } 57 | *this = IP(net.ParseIP(string(data[1 : len(data)-1]))) 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /src/gogopb_both/log.proto: -------------------------------------------------------------------------------- 1 | package proto; 2 | 3 | option go_package = "gogopb"; 4 | 5 | import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 6 | 7 | option (gogoproto.gostring_all) = false; 8 | option (gogoproto.verbose_equal_all) = false; 9 | option (gogoproto.equal_all) = true; 10 | option (gogoproto.populate_all) = true; 11 | option (gogoproto.stringer_all) = true; 12 | option (gogoproto.goproto_enum_prefix_all) = true; 13 | option (gogoproto.goproto_stringer_all) = false; 14 | option (gogoproto.testgen_all) = true; 15 | option (gogoproto.benchgen_all) = true; 16 | option (gogoproto.description_all) = false; 17 | option (gogoproto.unsafe_unmarshaler_all) = true; 18 | option (gogoproto.unsafe_marshaler_all) = true; 19 | option (gogoproto.sizer_all) = true; 20 | 21 | message HTTP { 22 | enum Protocol { 23 | HTTP_PROTOCOL_UNKNOWN = 0; 24 | HTTP10 = 1; 25 | HTTP11 = 2; 26 | } 27 | optional Protocol protocol = 1 [(gogoproto.nullable) = false]; 28 | 29 | optional uint32 status = 2 [(gogoproto.nullable) = false]; 30 | optional uint32 hostStatus = 3 [(gogoproto.nullable) = false]; 31 | optional uint32 upStatus = 4 [(gogoproto.nullable) = false]; 32 | 33 | enum Method { 34 | METHOD_UNKNOWN = 0; 35 | GET = 1; 36 | POST = 2; 37 | DELETE = 3; 38 | PUT = 4; 39 | HEAD = 5; 40 | PURGE = 6; 41 | OPTIONS = 7; 42 | PROPFIND = 8; 43 | MKCOL = 9; 44 | PATCH = 10; 45 | } 46 | optional Method method = 5 [(gogoproto.nullable) = false]; 47 | 48 | optional string contentType = 6 [(gogoproto.nullable) = false]; 49 | optional string userAgent = 7 [(gogoproto.nullable) = false]; 50 | optional string referer = 8 [(gogoproto.nullable) = false]; 51 | optional string requestURI = 9 [(gogoproto.nullable) = false]; 52 | } 53 | 54 | enum CacheStatus { 55 | CACHESTATUS_UNKNOWN = 0; 56 | MISS = 1; 57 | EXPIRED = 2; 58 | HIT = 3; 59 | } 60 | 61 | message Origin { 62 | optional bytes ip = 1 [(gogoproto.customtype) = "IP", (gogoproto.nullable) = false]; 63 | optional uint32 port = 2 [(gogoproto.nullable) = false]; 64 | optional string hostname = 3 [(gogoproto.nullable) = false]; 65 | enum Protocol { 66 | ORIGIN_PROTOCOL_UNKNOWN = 0; 67 | HTTP = 1; 68 | HTTPS = 2; 69 | } 70 | optional Protocol protocol = 4 [(gogoproto.nullable) = false]; 71 | } 72 | 73 | enum ZonePlan { 74 | ZONEPLAN_UNKNOWN = 0; 75 | FREE = 1; 76 | PRO = 2; 77 | BIZ = 3; 78 | ENT = 4; 79 | } 80 | 81 | message Log { 82 | optional sfixed64 timestamp = 1 [(gogoproto.nullable) = false]; 83 | optional uint32 zoneId = 2 [(gogoproto.nullable) = false]; 84 | optional ZonePlan zonePlan = 3 [(gogoproto.nullable) = false]; 85 | optional HTTP http = 4 [(gogoproto.nullable) = false]; 86 | optional Origin origin = 5 [(gogoproto.nullable) = false]; 87 | optional Country country = 6 [(gogoproto.nullable) = false]; 88 | optional CacheStatus cacheStatus = 7 [(gogoproto.nullable) = false]; 89 | optional bytes serverIp = 8 [(gogoproto.customtype) = "IP", (gogoproto.nullable) = false]; 90 | optional string serverName = 9 [(gogoproto.nullable) = false]; 91 | optional bytes remoteIp = 10 [(gogoproto.customtype) = "IP", (gogoproto.nullable) = false]; 92 | optional uint64 bytesDlv = 11 [(gogoproto.nullable) = false]; 93 | optional string rayId = 12 [(gogoproto.nullable) = false]; 94 | } 95 | 96 | enum Country { 97 | UNKNOWN = 0; 98 | A1 = 1; 99 | A2 = 2; 100 | O1 = 3; 101 | AD = 4; 102 | AE = 5; 103 | AF = 6; 104 | AG = 7; 105 | AI = 8; 106 | AL = 9; 107 | AM = 10; 108 | AO = 11; 109 | AP = 12; 110 | AQ = 13; 111 | AR = 14; 112 | AS = 15; 113 | AT = 16; 114 | AU = 17; 115 | AW = 18; 116 | AX = 19; 117 | AZ = 20; 118 | BA = 21; 119 | BB = 22; 120 | BD = 23; 121 | BE = 24; 122 | BF = 25; 123 | BG = 26; 124 | BH = 27; 125 | BI = 28; 126 | BJ = 29; 127 | BL = 30; 128 | BM = 31; 129 | BN = 32; 130 | BO = 33; 131 | BQ = 34; 132 | BR = 35; 133 | BS = 36; 134 | BT = 37; 135 | BV = 38; 136 | BW = 39; 137 | BY = 40; 138 | BZ = 41; 139 | CA = 42; 140 | CC = 43; 141 | CD = 44; 142 | CF = 45; 143 | CG = 46; 144 | CH = 47; 145 | CI = 48; 146 | CK = 49; 147 | CL = 50; 148 | CM = 51; 149 | CN = 52; 150 | CO = 53; 151 | CR = 54; 152 | CU = 55; 153 | CV = 56; 154 | CW = 57; 155 | CX = 58; 156 | CY = 59; 157 | CZ = 60; 158 | DE = 61; 159 | DJ = 62; 160 | DK = 63; 161 | DM = 64; 162 | DO = 65; 163 | DZ = 66; 164 | EC = 67; 165 | EE = 68; 166 | EG = 69; 167 | EH = 70; 168 | ER = 71; 169 | ES = 72; 170 | ET = 73; 171 | EU = 74; 172 | FI = 75; 173 | FJ = 76; 174 | FK = 77; 175 | FM = 78; 176 | FO = 79; 177 | FR = 80; 178 | GA = 81; 179 | GB = 82; 180 | GD = 83; 181 | GE = 84; 182 | GF = 85; 183 | GG = 86; 184 | GH = 87; 185 | GI = 88; 186 | GL = 89; 187 | GM = 90; 188 | GN = 91; 189 | GP = 92; 190 | GQ = 93; 191 | GR = 94; 192 | GS = 95; 193 | GT = 96; 194 | GU = 97; 195 | GW = 98; 196 | GY = 99; 197 | HK = 100; 198 | HM = 101; 199 | HN = 102; 200 | HR = 103; 201 | HT = 104; 202 | HU = 105; 203 | ID = 106; 204 | IE = 107; 205 | IL = 108; 206 | IM = 109; 207 | IN = 110; 208 | IO = 111; 209 | IQ = 112; 210 | IR = 113; 211 | IS = 114; 212 | IT = 115; 213 | JE = 116; 214 | JM = 117; 215 | JO = 118; 216 | JP = 119; 217 | KE = 120; 218 | KG = 121; 219 | KH = 122; 220 | KI = 123; 221 | KM = 124; 222 | KN = 125; 223 | KP = 126; 224 | KR = 127; 225 | KW = 128; 226 | KY = 129; 227 | KZ = 130; 228 | LA = 131; 229 | LB = 132; 230 | LC = 133; 231 | LI = 134; 232 | LK = 135; 233 | LR = 136; 234 | LS = 137; 235 | LT = 138; 236 | LU = 139; 237 | LV = 140; 238 | LY = 141; 239 | MA = 142; 240 | MC = 143; 241 | MD = 144; 242 | ME = 145; 243 | MF = 146; 244 | MG = 147; 245 | MH = 148; 246 | MK = 149; 247 | ML = 150; 248 | MM = 151; 249 | MN = 152; 250 | MO = 153; 251 | MP = 154; 252 | MQ = 155; 253 | MR = 156; 254 | MS = 157; 255 | MT = 158; 256 | MU = 159; 257 | MV = 160; 258 | MW = 161; 259 | MX = 162; 260 | MY = 163; 261 | MZ = 164; 262 | NA = 165; 263 | NC = 166; 264 | NE = 167; 265 | NF = 168; 266 | NG = 169; 267 | NI = 170; 268 | NL = 171; 269 | NO = 172; 270 | NP = 173; 271 | NR = 174; 272 | NU = 175; 273 | NZ = 176; 274 | OM = 177; 275 | PA = 178; 276 | PE = 179; 277 | PF = 180; 278 | PG = 181; 279 | PH = 182; 280 | PK = 183; 281 | PL = 184; 282 | PM = 185; 283 | PN = 186; 284 | PR = 187; 285 | PS = 188; 286 | PT = 189; 287 | PW = 190; 288 | PY = 191; 289 | QA = 192; 290 | RE = 193; 291 | RO = 194; 292 | RS = 195; 293 | RU = 196; 294 | RW = 197; 295 | SA = 198; 296 | SB = 199; 297 | SC = 200; 298 | SD = 201; 299 | SE = 202; 300 | SG = 203; 301 | SH = 204; 302 | SI = 205; 303 | SJ = 206; 304 | SK = 207; 305 | SL = 208; 306 | SM = 209; 307 | SN = 210; 308 | SO = 211; 309 | SR = 212; 310 | SS = 213; 311 | ST = 214; 312 | SV = 215; 313 | SX = 216; 314 | SY = 217; 315 | SZ = 218; 316 | TC = 219; 317 | TD = 220; 318 | TF = 221; 319 | TG = 222; 320 | TH = 223; 321 | TJ = 224; 322 | TK = 225; 323 | TL = 226; 324 | TM = 227; 325 | TN = 228; 326 | TO = 229; 327 | TR = 230; 328 | TT = 231; 329 | TV = 232; 330 | TW = 233; 331 | TZ = 234; 332 | UA = 235; 333 | UG = 236; 334 | UM = 237; 335 | US = 238; 336 | UY = 239; 337 | UZ = 240; 338 | VA = 241; 339 | VC = 242; 340 | VE = 243; 341 | VG = 244; 342 | VI = 245; 343 | VN = 246; 344 | VU = 247; 345 | WF = 248; 346 | WS = 249; 347 | XX = 250; 348 | YE = 251; 349 | YT = 252; 350 | ZA = 253; 351 | ZM = 254; 352 | ZW = 255; 353 | } 354 | -------------------------------------------------------------------------------- /src/gogopb_nullable/ip.go: -------------------------------------------------------------------------------- 1 | package gogopb 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "net" 7 | ) 8 | 9 | type IP net.IP 10 | 11 | func (this IP) Marshal() ([]byte, error) { 12 | return []byte(this), nil 13 | } 14 | 15 | func (this IP) MarshalTo(data []byte) (int, error) { 16 | n := copy(data, this) 17 | return n, nil 18 | } 19 | 20 | func (this *IP) Unmarshal(data []byte) error { 21 | if data == nil { 22 | *this = nil 23 | return nil 24 | } 25 | if len(*this) != len(data) { 26 | *this = IP(make([]byte, len(data))) 27 | } 28 | copy(*this, data) 29 | return nil 30 | } 31 | 32 | func (this IP) Size() int { 33 | return len(this) 34 | } 35 | 36 | type rander interface { 37 | Int63() int64 38 | } 39 | 40 | func NewPopulatedIP(r rander) *IP { 41 | ip := IP(net.IPv4(1, 2, 3, 4)) 42 | return &ip 43 | } 44 | 45 | func (this IP) Equal(other IP) bool { 46 | return bytes.Equal(this, other) 47 | } 48 | 49 | func (this IP) MarshalJSON() ([]byte, error) { 50 | return []byte("\"" + net.IP(this).String() + "\""), nil 51 | } 52 | 53 | func (this *IP) UnmarshalJSON(data []byte) error { 54 | if len(data) < 2 { 55 | return io.ErrShortBuffer 56 | } 57 | *this = IP(net.ParseIP(string(data[1 : len(data)-1]))) 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /src/gogopb_nullable/log.proto: -------------------------------------------------------------------------------- 1 | package proto; 2 | 3 | option go_package = "gogopb"; 4 | 5 | import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 6 | 7 | option (gogoproto.gostring_all) = false; 8 | option (gogoproto.verbose_equal_all) = false; 9 | option (gogoproto.equal_all) = true; 10 | option (gogoproto.populate_all) = true; 11 | option (gogoproto.stringer_all) = true; 12 | option (gogoproto.goproto_enum_prefix_all) = true; 13 | option (gogoproto.goproto_stringer_all) = false; 14 | option (gogoproto.testgen_all) = true; 15 | option (gogoproto.benchgen_all) = true; 16 | option (gogoproto.description_all) = false; 17 | option (gogoproto.unsafe_unmarshaler_all) = false; 18 | option (gogoproto.unsafe_marshaler_all) = false; 19 | option (gogoproto.sizer_all) = true; 20 | 21 | message HTTP { 22 | enum Protocol { 23 | HTTP_PROTOCOL_UNKNOWN = 0; 24 | HTTP10 = 1; 25 | HTTP11 = 2; 26 | } 27 | optional Protocol protocol = 1 [(gogoproto.nullable) = false]; 28 | 29 | optional uint32 status = 2 [(gogoproto.nullable) = false]; 30 | optional uint32 hostStatus = 3 [(gogoproto.nullable) = false]; 31 | optional uint32 upStatus = 4 [(gogoproto.nullable) = false]; 32 | 33 | enum Method { 34 | METHOD_UNKNOWN = 0; 35 | GET = 1; 36 | POST = 2; 37 | DELETE = 3; 38 | PUT = 4; 39 | HEAD = 5; 40 | PURGE = 6; 41 | OPTIONS = 7; 42 | PROPFIND = 8; 43 | MKCOL = 9; 44 | PATCH = 10; 45 | } 46 | optional Method method = 5 [(gogoproto.nullable) = false]; 47 | 48 | optional string contentType = 6 [(gogoproto.nullable) = false]; 49 | optional string userAgent = 7 [(gogoproto.nullable) = false]; 50 | optional string referer = 8 [(gogoproto.nullable) = false]; 51 | optional string requestURI = 9 [(gogoproto.nullable) = false]; 52 | } 53 | 54 | enum CacheStatus { 55 | CACHESTATUS_UNKNOWN = 0; 56 | MISS = 1; 57 | EXPIRED = 2; 58 | HIT = 3; 59 | } 60 | 61 | message Origin { 62 | optional bytes ip = 1 [(gogoproto.customtype) = "IP", (gogoproto.nullable) = false]; 63 | optional uint32 port = 2 [(gogoproto.nullable) = false]; 64 | optional string hostname = 3 [(gogoproto.nullable) = false]; 65 | enum Protocol { 66 | ORIGIN_PROTOCOL_UNKNOWN = 0; 67 | HTTP = 1; 68 | HTTPS = 2; 69 | } 70 | optional Protocol protocol = 4 [(gogoproto.nullable) = false]; 71 | } 72 | 73 | enum ZonePlan { 74 | ZONEPLAN_UNKNOWN = 0; 75 | FREE = 1; 76 | PRO = 2; 77 | BIZ = 3; 78 | ENT = 4; 79 | } 80 | 81 | message Log { 82 | optional sfixed64 timestamp = 1 [(gogoproto.nullable) = false]; 83 | optional uint32 zoneId = 2 [(gogoproto.nullable) = false]; 84 | optional ZonePlan zonePlan = 3 [(gogoproto.nullable) = false]; 85 | optional HTTP http = 4 [(gogoproto.nullable) = false]; 86 | optional Origin origin = 5 [(gogoproto.nullable) = false]; 87 | optional Country country = 6 [(gogoproto.nullable) = false]; 88 | optional CacheStatus cacheStatus = 7 [(gogoproto.nullable) = false]; 89 | optional bytes serverIp = 8 [(gogoproto.customtype) = "IP", (gogoproto.nullable) = false]; 90 | optional string serverName = 9 [(gogoproto.nullable) = false]; 91 | optional bytes remoteIp = 10 [(gogoproto.customtype) = "IP", (gogoproto.nullable) = false]; 92 | optional uint64 bytesDlv = 11 [(gogoproto.nullable) = false]; 93 | optional string rayId = 12 [(gogoproto.nullable) = false]; 94 | } 95 | 96 | enum Country { 97 | UNKNOWN = 0; 98 | A1 = 1; 99 | A2 = 2; 100 | O1 = 3; 101 | AD = 4; 102 | AE = 5; 103 | AF = 6; 104 | AG = 7; 105 | AI = 8; 106 | AL = 9; 107 | AM = 10; 108 | AO = 11; 109 | AP = 12; 110 | AQ = 13; 111 | AR = 14; 112 | AS = 15; 113 | AT = 16; 114 | AU = 17; 115 | AW = 18; 116 | AX = 19; 117 | AZ = 20; 118 | BA = 21; 119 | BB = 22; 120 | BD = 23; 121 | BE = 24; 122 | BF = 25; 123 | BG = 26; 124 | BH = 27; 125 | BI = 28; 126 | BJ = 29; 127 | BL = 30; 128 | BM = 31; 129 | BN = 32; 130 | BO = 33; 131 | BQ = 34; 132 | BR = 35; 133 | BS = 36; 134 | BT = 37; 135 | BV = 38; 136 | BW = 39; 137 | BY = 40; 138 | BZ = 41; 139 | CA = 42; 140 | CC = 43; 141 | CD = 44; 142 | CF = 45; 143 | CG = 46; 144 | CH = 47; 145 | CI = 48; 146 | CK = 49; 147 | CL = 50; 148 | CM = 51; 149 | CN = 52; 150 | CO = 53; 151 | CR = 54; 152 | CU = 55; 153 | CV = 56; 154 | CW = 57; 155 | CX = 58; 156 | CY = 59; 157 | CZ = 60; 158 | DE = 61; 159 | DJ = 62; 160 | DK = 63; 161 | DM = 64; 162 | DO = 65; 163 | DZ = 66; 164 | EC = 67; 165 | EE = 68; 166 | EG = 69; 167 | EH = 70; 168 | ER = 71; 169 | ES = 72; 170 | ET = 73; 171 | EU = 74; 172 | FI = 75; 173 | FJ = 76; 174 | FK = 77; 175 | FM = 78; 176 | FO = 79; 177 | FR = 80; 178 | GA = 81; 179 | GB = 82; 180 | GD = 83; 181 | GE = 84; 182 | GF = 85; 183 | GG = 86; 184 | GH = 87; 185 | GI = 88; 186 | GL = 89; 187 | GM = 90; 188 | GN = 91; 189 | GP = 92; 190 | GQ = 93; 191 | GR = 94; 192 | GS = 95; 193 | GT = 96; 194 | GU = 97; 195 | GW = 98; 196 | GY = 99; 197 | HK = 100; 198 | HM = 101; 199 | HN = 102; 200 | HR = 103; 201 | HT = 104; 202 | HU = 105; 203 | ID = 106; 204 | IE = 107; 205 | IL = 108; 206 | IM = 109; 207 | IN = 110; 208 | IO = 111; 209 | IQ = 112; 210 | IR = 113; 211 | IS = 114; 212 | IT = 115; 213 | JE = 116; 214 | JM = 117; 215 | JO = 118; 216 | JP = 119; 217 | KE = 120; 218 | KG = 121; 219 | KH = 122; 220 | KI = 123; 221 | KM = 124; 222 | KN = 125; 223 | KP = 126; 224 | KR = 127; 225 | KW = 128; 226 | KY = 129; 227 | KZ = 130; 228 | LA = 131; 229 | LB = 132; 230 | LC = 133; 231 | LI = 134; 232 | LK = 135; 233 | LR = 136; 234 | LS = 137; 235 | LT = 138; 236 | LU = 139; 237 | LV = 140; 238 | LY = 141; 239 | MA = 142; 240 | MC = 143; 241 | MD = 144; 242 | ME = 145; 243 | MF = 146; 244 | MG = 147; 245 | MH = 148; 246 | MK = 149; 247 | ML = 150; 248 | MM = 151; 249 | MN = 152; 250 | MO = 153; 251 | MP = 154; 252 | MQ = 155; 253 | MR = 156; 254 | MS = 157; 255 | MT = 158; 256 | MU = 159; 257 | MV = 160; 258 | MW = 161; 259 | MX = 162; 260 | MY = 163; 261 | MZ = 164; 262 | NA = 165; 263 | NC = 166; 264 | NE = 167; 265 | NF = 168; 266 | NG = 169; 267 | NI = 170; 268 | NL = 171; 269 | NO = 172; 270 | NP = 173; 271 | NR = 174; 272 | NU = 175; 273 | NZ = 176; 274 | OM = 177; 275 | PA = 178; 276 | PE = 179; 277 | PF = 180; 278 | PG = 181; 279 | PH = 182; 280 | PK = 183; 281 | PL = 184; 282 | PM = 185; 283 | PN = 186; 284 | PR = 187; 285 | PS = 188; 286 | PT = 189; 287 | PW = 190; 288 | PY = 191; 289 | QA = 192; 290 | RE = 193; 291 | RO = 194; 292 | RS = 195; 293 | RU = 196; 294 | RW = 197; 295 | SA = 198; 296 | SB = 199; 297 | SC = 200; 298 | SD = 201; 299 | SE = 202; 300 | SG = 203; 301 | SH = 204; 302 | SI = 205; 303 | SJ = 206; 304 | SK = 207; 305 | SL = 208; 306 | SM = 209; 307 | SN = 210; 308 | SO = 211; 309 | SR = 212; 310 | SS = 213; 311 | ST = 214; 312 | SV = 215; 313 | SX = 216; 314 | SY = 217; 315 | SZ = 218; 316 | TC = 219; 317 | TD = 220; 318 | TF = 221; 319 | TG = 222; 320 | TH = 223; 321 | TJ = 224; 322 | TK = 225; 323 | TL = 226; 324 | TM = 227; 325 | TN = 228; 326 | TO = 229; 327 | TR = 230; 328 | TT = 231; 329 | TV = 232; 330 | TW = 233; 331 | TZ = 234; 332 | UA = 235; 333 | UG = 236; 334 | UM = 237; 335 | US = 238; 336 | UY = 239; 337 | UZ = 240; 338 | VA = 241; 339 | VC = 242; 340 | VE = 243; 341 | VG = 244; 342 | VI = 245; 343 | VN = 246; 344 | VU = 247; 345 | WF = 248; 346 | WS = 249; 347 | XX = 250; 348 | YE = 251; 349 | YT = 252; 350 | ZA = 253; 351 | ZM = 254; 352 | ZW = 255; 353 | } 354 | -------------------------------------------------------------------------------- /src/gogopb_unsafe/ip.go: -------------------------------------------------------------------------------- 1 | package gogopb 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "net" 7 | ) 8 | 9 | type IP net.IP 10 | 11 | func (this IP) Marshal() ([]byte, error) { 12 | return []byte(this), nil 13 | } 14 | 15 | func (this IP) MarshalTo(data []byte) (int, error) { 16 | n := copy(data, this) 17 | return n, nil 18 | } 19 | 20 | func (this *IP) Unmarshal(data []byte) error { 21 | if data == nil { 22 | *this = nil 23 | return nil 24 | } 25 | if len(*this) != len(data) { 26 | *this = IP(make([]byte, len(data))) 27 | } 28 | copy(*this, data) 29 | return nil 30 | } 31 | 32 | func (this IP) Size() int { 33 | return len(this) 34 | } 35 | 36 | type rander interface { 37 | Int63() int64 38 | } 39 | 40 | func NewPopulatedIP(r rander) *IP { 41 | ip := IP(net.IPv4(1, 2, 3, 4)) 42 | return &ip 43 | } 44 | 45 | func (this IP) Equal(other IP) bool { 46 | return bytes.Equal(this, other) 47 | } 48 | 49 | func (this IP) MarshalJSON() ([]byte, error) { 50 | return []byte("\"" + net.IP(this).String() + "\""), nil 51 | } 52 | 53 | func (this *IP) UnmarshalJSON(data []byte) error { 54 | if len(data) < 2 { 55 | return io.ErrShortBuffer 56 | } 57 | *this = IP(net.ParseIP(string(data[1 : len(data)-1]))) 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /src/gogopb_unsafe/log.proto: -------------------------------------------------------------------------------- 1 | package proto; 2 | 3 | option go_package = "gogopb"; 4 | 5 | import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 6 | 7 | option (gogoproto.gostring_all) = false; 8 | option (gogoproto.verbose_equal_all) = false; 9 | option (gogoproto.equal_all) = true; 10 | option (gogoproto.populate_all) = true; 11 | option (gogoproto.stringer_all) = true; 12 | option (gogoproto.goproto_enum_prefix_all) = true; 13 | option (gogoproto.goproto_stringer_all) = false; 14 | option (gogoproto.testgen_all) = true; 15 | option (gogoproto.benchgen_all) = true; 16 | option (gogoproto.description_all) = false; 17 | option (gogoproto.unsafe_unmarshaler_all) = true; 18 | option (gogoproto.unsafe_marshaler_all) = true; 19 | option (gogoproto.sizer_all) = true; 20 | 21 | message HTTP { 22 | enum Protocol { 23 | HTTP_PROTOCOL_UNKNOWN = 0; 24 | HTTP10 = 1; 25 | HTTP11 = 2; 26 | } 27 | optional Protocol protocol = 1; 28 | 29 | optional uint32 status = 2; 30 | optional uint32 hostStatus = 3; 31 | optional uint32 upStatus = 4; 32 | 33 | enum Method { 34 | METHOD_UNKNOWN = 0; 35 | GET = 1; 36 | POST = 2; 37 | DELETE = 3; 38 | PUT = 4; 39 | HEAD = 5; 40 | PURGE = 6; 41 | OPTIONS = 7; 42 | PROPFIND = 8; 43 | MKCOL = 9; 44 | PATCH = 10; 45 | } 46 | optional Method method = 5; 47 | 48 | optional string contentType = 6; 49 | optional string userAgent = 7; 50 | optional string referer = 8; 51 | optional string requestURI = 9; 52 | } 53 | 54 | enum CacheStatus { 55 | CACHESTATUS_UNKNOWN = 0; 56 | MISS = 1; 57 | EXPIRED = 2; 58 | HIT = 3; 59 | } 60 | 61 | message Origin { 62 | optional bytes ip = 1 [(gogoproto.customtype) = "IP"]; 63 | optional uint32 port = 2; 64 | optional string hostname = 3; 65 | enum Protocol { 66 | ORIGIN_PROTOCOL_UNKNOWN = 0; 67 | HTTP = 1; 68 | HTTPS = 2; 69 | } 70 | optional Protocol protocol = 4; 71 | } 72 | 73 | enum ZonePlan { 74 | ZONEPLAN_UNKNOWN = 0; 75 | FREE = 1; 76 | PRO = 2; 77 | BIZ = 3; 78 | ENT = 4; 79 | } 80 | 81 | message Log { 82 | optional sfixed64 timestamp = 1; 83 | optional uint32 zoneId = 2; 84 | optional ZonePlan zonePlan = 3; 85 | optional HTTP http = 4; 86 | optional Origin origin = 5; 87 | optional Country country = 6; 88 | optional CacheStatus cacheStatus = 7; 89 | optional bytes serverIp = 8 [(gogoproto.customtype) = "IP"]; 90 | optional string serverName = 9; 91 | optional bytes remoteIp = 10 [(gogoproto.customtype) = "IP"]; 92 | optional uint64 bytesDlv = 11; 93 | optional string rayId = 12; 94 | } 95 | 96 | enum Country { 97 | UNKNOWN = 0; 98 | A1 = 1; 99 | A2 = 2; 100 | O1 = 3; 101 | AD = 4; 102 | AE = 5; 103 | AF = 6; 104 | AG = 7; 105 | AI = 8; 106 | AL = 9; 107 | AM = 10; 108 | AO = 11; 109 | AP = 12; 110 | AQ = 13; 111 | AR = 14; 112 | AS = 15; 113 | AT = 16; 114 | AU = 17; 115 | AW = 18; 116 | AX = 19; 117 | AZ = 20; 118 | BA = 21; 119 | BB = 22; 120 | BD = 23; 121 | BE = 24; 122 | BF = 25; 123 | BG = 26; 124 | BH = 27; 125 | BI = 28; 126 | BJ = 29; 127 | BL = 30; 128 | BM = 31; 129 | BN = 32; 130 | BO = 33; 131 | BQ = 34; 132 | BR = 35; 133 | BS = 36; 134 | BT = 37; 135 | BV = 38; 136 | BW = 39; 137 | BY = 40; 138 | BZ = 41; 139 | CA = 42; 140 | CC = 43; 141 | CD = 44; 142 | CF = 45; 143 | CG = 46; 144 | CH = 47; 145 | CI = 48; 146 | CK = 49; 147 | CL = 50; 148 | CM = 51; 149 | CN = 52; 150 | CO = 53; 151 | CR = 54; 152 | CU = 55; 153 | CV = 56; 154 | CW = 57; 155 | CX = 58; 156 | CY = 59; 157 | CZ = 60; 158 | DE = 61; 159 | DJ = 62; 160 | DK = 63; 161 | DM = 64; 162 | DO = 65; 163 | DZ = 66; 164 | EC = 67; 165 | EE = 68; 166 | EG = 69; 167 | EH = 70; 168 | ER = 71; 169 | ES = 72; 170 | ET = 73; 171 | EU = 74; 172 | FI = 75; 173 | FJ = 76; 174 | FK = 77; 175 | FM = 78; 176 | FO = 79; 177 | FR = 80; 178 | GA = 81; 179 | GB = 82; 180 | GD = 83; 181 | GE = 84; 182 | GF = 85; 183 | GG = 86; 184 | GH = 87; 185 | GI = 88; 186 | GL = 89; 187 | GM = 90; 188 | GN = 91; 189 | GP = 92; 190 | GQ = 93; 191 | GR = 94; 192 | GS = 95; 193 | GT = 96; 194 | GU = 97; 195 | GW = 98; 196 | GY = 99; 197 | HK = 100; 198 | HM = 101; 199 | HN = 102; 200 | HR = 103; 201 | HT = 104; 202 | HU = 105; 203 | ID = 106; 204 | IE = 107; 205 | IL = 108; 206 | IM = 109; 207 | IN = 110; 208 | IO = 111; 209 | IQ = 112; 210 | IR = 113; 211 | IS = 114; 212 | IT = 115; 213 | JE = 116; 214 | JM = 117; 215 | JO = 118; 216 | JP = 119; 217 | KE = 120; 218 | KG = 121; 219 | KH = 122; 220 | KI = 123; 221 | KM = 124; 222 | KN = 125; 223 | KP = 126; 224 | KR = 127; 225 | KW = 128; 226 | KY = 129; 227 | KZ = 130; 228 | LA = 131; 229 | LB = 132; 230 | LC = 133; 231 | LI = 134; 232 | LK = 135; 233 | LR = 136; 234 | LS = 137; 235 | LT = 138; 236 | LU = 139; 237 | LV = 140; 238 | LY = 141; 239 | MA = 142; 240 | MC = 143; 241 | MD = 144; 242 | ME = 145; 243 | MF = 146; 244 | MG = 147; 245 | MH = 148; 246 | MK = 149; 247 | ML = 150; 248 | MM = 151; 249 | MN = 152; 250 | MO = 153; 251 | MP = 154; 252 | MQ = 155; 253 | MR = 156; 254 | MS = 157; 255 | MT = 158; 256 | MU = 159; 257 | MV = 160; 258 | MW = 161; 259 | MX = 162; 260 | MY = 163; 261 | MZ = 164; 262 | NA = 165; 263 | NC = 166; 264 | NE = 167; 265 | NF = 168; 266 | NG = 169; 267 | NI = 170; 268 | NL = 171; 269 | NO = 172; 270 | NP = 173; 271 | NR = 174; 272 | NU = 175; 273 | NZ = 176; 274 | OM = 177; 275 | PA = 178; 276 | PE = 179; 277 | PF = 180; 278 | PG = 181; 279 | PH = 182; 280 | PK = 183; 281 | PL = 184; 282 | PM = 185; 283 | PN = 186; 284 | PR = 187; 285 | PS = 188; 286 | PT = 189; 287 | PW = 190; 288 | PY = 191; 289 | QA = 192; 290 | RE = 193; 291 | RO = 194; 292 | RS = 195; 293 | RU = 196; 294 | RW = 197; 295 | SA = 198; 296 | SB = 199; 297 | SC = 200; 298 | SD = 201; 299 | SE = 202; 300 | SG = 203; 301 | SH = 204; 302 | SI = 205; 303 | SJ = 206; 304 | SK = 207; 305 | SL = 208; 306 | SM = 209; 307 | SN = 210; 308 | SO = 211; 309 | SR = 212; 310 | SS = 213; 311 | ST = 214; 312 | SV = 215; 313 | SX = 216; 314 | SY = 217; 315 | SZ = 218; 316 | TC = 219; 317 | TD = 220; 318 | TF = 221; 319 | TG = 222; 320 | TH = 223; 321 | TJ = 224; 322 | TK = 225; 323 | TL = 226; 324 | TM = 227; 325 | TN = 228; 326 | TO = 229; 327 | TR = 230; 328 | TT = 231; 329 | TV = 232; 330 | TW = 233; 331 | TZ = 234; 332 | UA = 235; 333 | UG = 236; 334 | UM = 237; 335 | US = 238; 336 | UY = 239; 337 | UZ = 240; 338 | VA = 241; 339 | VC = 242; 340 | VE = 243; 341 | VG = 244; 342 | VI = 245; 343 | VN = 246; 344 | VU = 247; 345 | WF = 248; 346 | WS = 249; 347 | XX = 250; 348 | YE = 251; 349 | YT = 252; 350 | ZA = 253; 351 | ZM = 254; 352 | ZW = 255; 353 | } 354 | -------------------------------------------------------------------------------- /src/goser/bench_test.go: -------------------------------------------------------------------------------- 1 | package goser 2 | 3 | import ( 4 | "bytes" 5 | "capnp" 6 | "encoding/json" 7 | "github.com/glycerine/go-capnproto" 8 | "github.com/golang/protobuf/proto" 9 | "gogopb_both" 10 | "pb" 11 | "testing" 12 | ) 13 | 14 | func BenchmarkPopulatePb(b *testing.B) { 15 | var record pb.Log 16 | b.ResetTimer() 17 | for i := 0; i < b.N; i++ { 18 | newPbLog(&record) 19 | } 20 | } 21 | 22 | func BenchmarkPopulateGogopb(b *testing.B) { 23 | var record gogopb.Log 24 | b.ResetTimer() 25 | for i := 0; i < b.N; i++ { 26 | newGogopbLog(&record) 27 | } 28 | } 29 | 30 | func BenchmarkPopulateCapnp(b *testing.B) { 31 | buf := make([]byte, 1<<20) 32 | b.ResetTimer() 33 | for i := 0; i < b.N; i++ { 34 | segment := capn.NewBuffer(buf[:0]) 35 | record := capnp.NewRootLog(segment) 36 | newCapnpLog(&record) 37 | } 38 | } 39 | 40 | func BenchmarkMarshalJSON(b *testing.B) { 41 | var record gogopb.Log 42 | newGogopbLog(&record) 43 | 44 | buf, err := json.Marshal(&record) 45 | if err != nil { 46 | b.Fatalf("Marshal: %v", err) 47 | } 48 | b.SetBytes(int64(len(buf))) 49 | 50 | buffer := bytes.NewBuffer(make([]byte, 1<<20)) 51 | 52 | b.ResetTimer() 53 | for i := 0; i < b.N; i++ { 54 | buffer.Reset() 55 | encoder := json.NewEncoder(buffer) 56 | err := encoder.Encode(&record) 57 | if err != nil { 58 | b.Fatalf("Marshal: %v", err) 59 | } 60 | } 61 | } 62 | 63 | func BenchmarkMarshalPb(b *testing.B) { 64 | var record pb.Log 65 | newPbLog(&record) 66 | 67 | buf, err := proto.Marshal(&record) 68 | if err != nil { 69 | b.Fatalf("Marshal: %v", err) 70 | } 71 | b.SetBytes(int64(len(buf))) 72 | 73 | buffer := proto.NewBuffer(make([]byte, 1<<20)) 74 | 75 | b.ResetTimer() 76 | for i := 0; i < b.N; i++ { 77 | buffer.Reset() 78 | err := buffer.Marshal(&record) 79 | if err != nil { 80 | b.Fatalf("Marshal: %v", err) 81 | } 82 | } 83 | } 84 | 85 | func BenchmarkMarshalGogopb(b *testing.B) { 86 | var record gogopb.Log 87 | newGogopbLog(&record) 88 | 89 | buf, err := proto.Marshal(&record) 90 | if err != nil { 91 | b.Fatalf("Marshal: %v", err) 92 | } 93 | b.SetBytes(int64(len(buf))) 94 | 95 | buffer := proto.NewBuffer(make([]byte, 1<<20)) 96 | 97 | b.ResetTimer() 98 | for i := 0; i < b.N; i++ { 99 | buffer.Reset() 100 | err := buffer.Marshal(&record) 101 | if err != nil { 102 | b.Fatalf("Marshal: %v", err) 103 | } 104 | } 105 | } 106 | 107 | func BenchmarkMarshalCapnp(b *testing.B) { 108 | segment := capn.NewBuffer(make([]byte, 0, 1<<20)) 109 | record := capnp.NewRootLog(segment) 110 | newCapnpLog(&record) 111 | 112 | var buf bytes.Buffer 113 | _, err := segment.WriteTo(&buf) 114 | if err != nil { 115 | b.Fatalf("WriteTo: %v", err) 116 | } 117 | b.SetBytes(int64(len(buf.Bytes()))) 118 | 119 | b.ResetTimer() 120 | for i := 0; i < b.N; i++ { 121 | buf.Reset() 122 | _, err := segment.WriteTo(&buf) 123 | if err != nil { 124 | b.Fatalf("WriteTo: %v", err) 125 | } 126 | } 127 | } 128 | 129 | func BenchmarkUnmarshalJSON(b *testing.B) { 130 | // generate the same marshalled buffer 131 | var record gogopb.Log 132 | newGogopbLog(&record) 133 | buf, err := json.Marshal(&record) 134 | if err != nil { 135 | b.Fatalf("Marshal: %v", err) 136 | } 137 | b.SetBytes(int64(len(buf))) 138 | 139 | var tmp gogopb.Log 140 | b.ResetTimer() 141 | for i := 0; i < b.N; i++ { 142 | err := json.Unmarshal(buf, &tmp) 143 | if err != nil { 144 | b.Fatalf("Unmarshal: %v", err) 145 | } 146 | } 147 | } 148 | 149 | func BenchmarkUnmarshalPb(b *testing.B) { 150 | var record pb.Log 151 | newPbLog(&record) 152 | buf, err := proto.Marshal(&record) 153 | if err != nil { 154 | b.Fatalf("Marshal: %v", err) 155 | } 156 | b.SetBytes(int64(len(buf))) 157 | 158 | var tmp pb.Log 159 | b.ResetTimer() 160 | for i := 0; i < b.N; i++ { 161 | err := proto.Unmarshal(buf, &tmp) 162 | if err != nil { 163 | b.Fatalf("Unmarshal: %v", err) 164 | } 165 | } 166 | } 167 | 168 | func BenchmarkUnmarshalGogopb(b *testing.B) { 169 | // generate the same marshalled buffer 170 | var record pb.Log 171 | newPbLog(&record) 172 | buf, err := proto.Marshal(&record) 173 | if err != nil { 174 | b.Fatalf("Marshal: %v", err) 175 | } 176 | b.SetBytes(int64(len(buf))) 177 | 178 | var tmp gogopb.Log 179 | b.ResetTimer() 180 | for i := 0; i < b.N; i++ { 181 | err := proto.Unmarshal(buf, &tmp) 182 | if err != nil { 183 | b.Fatalf("Unmarshal: %v", err) 184 | } 185 | } 186 | } 187 | 188 | func BenchmarkUnmarshalCapnp(b *testing.B) { 189 | segment := capn.NewBuffer(make([]byte, 0, 1<<20)) 190 | record := capnp.NewRootLog(segment) 191 | newCapnpLog(&record) 192 | 193 | var buf bytes.Buffer 194 | _, err := segment.WriteTo(&buf) 195 | if err != nil { 196 | b.Fatalf("WriteTo: %v", err) 197 | } 198 | b.SetBytes(int64(len(buf.Bytes()))) 199 | 200 | segmentBuf := bytes.NewBuffer(make([]byte, 0, 1<<20)) 201 | 202 | b.ResetTimer() 203 | for i := 0; i < b.N; i++ { 204 | r := bytes.NewBuffer(buf.Bytes()) 205 | seg, err := capn.ReadFromStream(r, segmentBuf) 206 | if err != nil { 207 | b.Fatalf("ReadFromStream: %v", err) 208 | } 209 | record := capnp.ReadRootLog(seg) 210 | _ = record 211 | } 212 | } 213 | 214 | func BenchmarkUnmarshalCapnpZeroCopy(b *testing.B) { 215 | segment := capn.NewBuffer(make([]byte, 0, 1<<20)) 216 | record := capnp.NewRootLog(segment) 217 | newCapnpLog(&record) 218 | 219 | var buf bytes.Buffer 220 | _, err := segment.WriteTo(&buf) 221 | if err != nil { 222 | b.Fatalf("WriteTo: %v", err) 223 | } 224 | b.SetBytes(int64(len(buf.Bytes()))) 225 | 226 | data := buf.Bytes() 227 | 228 | b.ResetTimer() 229 | for i := 0; i < b.N; i++ { 230 | seg, _, err := capn.ReadFromMemoryZeroCopy(data) 231 | if err != nil { 232 | b.Fatalf("ReadFromStream: %v", err) 233 | } 234 | record := capnp.ReadRootLog(seg) 235 | _ = record 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /src/goser/util_test.go: -------------------------------------------------------------------------------- 1 | package goser 2 | 3 | import ( 4 | "capnp" 5 | "github.com/golang/protobuf/proto" 6 | "gogopb_both" 7 | "net" 8 | "pb" 9 | "time" 10 | ) 11 | 12 | const userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36" 13 | 14 | func newPbLog(record *pb.Log) { 15 | record.Timestamp = proto.Int64(time.Now().UnixNano()) 16 | record.ZoneId = proto.Uint32(123456) 17 | record.ZonePlan = pb.ZonePlan_FREE.Enum() 18 | 19 | record.Http = &pb.HTTP{ 20 | Protocol: pb.HTTP_HTTP11.Enum(), 21 | Status: proto.Uint32(200), 22 | HostStatus: proto.Uint32(503), 23 | UpStatus: proto.Uint32(520), 24 | Method: pb.HTTP_GET.Enum(), 25 | ContentType: proto.String("text/html"), 26 | UserAgent: proto.String(userAgent), 27 | Referer: proto.String("https://www.cloudflare.com/"), 28 | RequestURI: proto.String("/cdn-cgi/trace"), 29 | } 30 | 31 | record.Origin = &pb.Origin{ 32 | Ip: []byte(net.IPv4(1, 2, 3, 4).To4()), 33 | Port: proto.Uint32(8080), 34 | Hostname: proto.String("www.example.com"), 35 | Protocol: pb.Origin_HTTPS.Enum(), 36 | } 37 | 38 | record.Country = pb.Country_US.Enum() 39 | record.CacheStatus = pb.CacheStatus_HIT.Enum() 40 | record.ServerIp = []byte(net.IPv4(192, 168, 1, 1).To4()) 41 | record.ServerName = proto.String("metal.cloudflare.com") 42 | record.RemoteIp = []byte(net.IPv4(10, 1, 2, 3).To4()) 43 | record.BytesDlv = proto.Uint64(123456) 44 | record.RayId = proto.String("10c73629cce30078-LAX") 45 | } 46 | 47 | func newGogopbLog(record *gogopb.Log) { 48 | record.Timestamp = time.Now().UnixNano() 49 | record.ZoneId = 123456 50 | record.ZonePlan = gogopb.ZonePlan_FREE 51 | 52 | record.Http = gogopb.HTTP{ 53 | Protocol: gogopb.HTTP_HTTP11, 54 | Status: 200, 55 | HostStatus: 503, 56 | UpStatus: 520, 57 | Method: gogopb.HTTP_GET, 58 | ContentType: "text/html", 59 | UserAgent: userAgent, 60 | Referer: "https://www.cloudflare.com/", 61 | RequestURI: "/cdn-cgi/trace", 62 | } 63 | 64 | record.Origin = gogopb.Origin{ 65 | Ip: gogopb.IP(net.IPv4(1, 2, 3, 4).To4()), 66 | Port: 8080, 67 | Hostname: "www.example.com", 68 | Protocol: gogopb.Origin_HTTPS, 69 | } 70 | 71 | record.Country = gogopb.Country_US 72 | record.CacheStatus = gogopb.CacheStatus_HIT 73 | record.ServerIp = gogopb.IP(net.IPv4(192, 168, 1, 1).To4()) 74 | record.ServerName = "metal.cloudflare.com" 75 | record.RemoteIp = gogopb.IP(net.IPv4(10, 1, 2, 3).To4()) 76 | record.BytesDlv = 123456 77 | record.RayId = "10c73629cce30078-LAX" 78 | } 79 | 80 | func newCapnpLog(record *capnp.Log) { 81 | record.SetTimestamp(time.Now().UnixNano()) 82 | record.SetZoneId(123456) 83 | record.SetZonePlan(capnp.ZONEPLAN_FREE) 84 | 85 | http := capnp.NewHTTP(record.Segment) 86 | record.SetHttp(http) 87 | http.SetProtocol(capnp.HTTPPROTOCOL_HTTP11) 88 | http.SetStatus(200) 89 | http.SetHostStatus(503) 90 | http.SetUpStatus(520) 91 | http.SetMethod(capnp.HTTPMETHOD_GET) 92 | http.SetContentType("text/html") 93 | http.SetUserAgent(userAgent) 94 | http.SetReferer("http://www.w3.org/hypertext/DataSources/Overview.html") 95 | http.SetRequestURI("/a9pPJR1.jpg") 96 | 97 | origin := capnp.NewOrigin(record.Segment) 98 | record.SetOrigin(origin) 99 | origin.SetIp([]byte(net.IPv4(1, 2, 3, 4).To4())) 100 | origin.SetPort(8080) 101 | origin.SetHostname("www.cloudflare.com") 102 | origin.SetProtocol(capnp.ORIGINPROTOCOL_HTTPS) 103 | 104 | record.SetCacheStatus(capnp.CACHESTATUS_HIT) 105 | record.SetServerIp([]byte(net.IPv4(192, 168, 1, 1).To4())) 106 | record.SetServerName("metal.cloudflare.com") 107 | record.SetRemoteIp([]byte(net.IPv4(10, 1, 2, 3).To4())) 108 | record.SetBytesDlv(123456) 109 | record.SetRayId("10c73629cce30078-LAX") 110 | } 111 | -------------------------------------------------------------------------------- /src/pb/log.proto: -------------------------------------------------------------------------------- 1 | package pb; 2 | 3 | message HTTP { 4 | enum Protocol { 5 | HTTP_PROTOCOL_UNKNOWN = 0; 6 | HTTP10 = 1; 7 | HTTP11 = 2; 8 | } 9 | optional Protocol protocol = 1; 10 | 11 | optional uint32 status = 2; 12 | optional uint32 hostStatus = 3; 13 | optional uint32 upStatus = 4; 14 | 15 | enum Method { 16 | METHOD_UNKNOWN = 0; 17 | GET = 1; 18 | POST = 2; 19 | DELETE = 3; 20 | PUT = 4; 21 | HEAD = 5; 22 | PURGE = 6; 23 | OPTIONS = 7; 24 | PROPFIND = 8; 25 | MKCOL = 9; 26 | PATCH = 10; 27 | } 28 | optional Method method = 5; 29 | 30 | optional string contentType = 6; 31 | optional string userAgent = 7; 32 | optional string referer = 8; 33 | optional string requestURI = 9; 34 | } 35 | 36 | enum CacheStatus { 37 | CACHESTATUS_UNKNOWN = 0; 38 | MISS = 1; 39 | EXPIRED = 2; 40 | HIT = 3; 41 | } 42 | 43 | message Origin { 44 | optional bytes ip = 1; 45 | optional uint32 port = 2; 46 | optional string hostname = 3; 47 | enum Protocol { 48 | ORIGIN_PROTOCOL_UNKNOWN = 0; 49 | HTTP = 1; 50 | HTTPS = 2; 51 | } 52 | optional Protocol protocol = 4; 53 | } 54 | 55 | enum ZonePlan { 56 | ZONEPLAN_UNKNOWN = 0; 57 | FREE = 1; 58 | PRO = 2; 59 | BIZ = 3; 60 | ENT = 4; 61 | } 62 | 63 | message Log { 64 | optional sfixed64 timestamp = 1; 65 | optional uint32 zoneId = 2; 66 | optional ZonePlan zonePlan = 3; 67 | optional HTTP http = 4; 68 | optional Origin origin = 5; 69 | optional Country country = 6; 70 | optional CacheStatus cacheStatus = 7; 71 | optional bytes serverIp = 8; 72 | optional string serverName = 9; 73 | optional bytes remoteIp = 10; 74 | optional uint64 bytesDlv = 11; 75 | optional string rayId = 12; 76 | } 77 | 78 | enum Country { 79 | UNKNOWN = 0; 80 | A1 = 1; 81 | A2 = 2; 82 | O1 = 3; 83 | AD = 4; 84 | AE = 5; 85 | AF = 6; 86 | AG = 7; 87 | AI = 8; 88 | AL = 9; 89 | AM = 10; 90 | AO = 11; 91 | AP = 12; 92 | AQ = 13; 93 | AR = 14; 94 | AS = 15; 95 | AT = 16; 96 | AU = 17; 97 | AW = 18; 98 | AX = 19; 99 | AZ = 20; 100 | BA = 21; 101 | BB = 22; 102 | BD = 23; 103 | BE = 24; 104 | BF = 25; 105 | BG = 26; 106 | BH = 27; 107 | BI = 28; 108 | BJ = 29; 109 | BL = 30; 110 | BM = 31; 111 | BN = 32; 112 | BO = 33; 113 | BQ = 34; 114 | BR = 35; 115 | BS = 36; 116 | BT = 37; 117 | BV = 38; 118 | BW = 39; 119 | BY = 40; 120 | BZ = 41; 121 | CA = 42; 122 | CC = 43; 123 | CD = 44; 124 | CF = 45; 125 | CG = 46; 126 | CH = 47; 127 | CI = 48; 128 | CK = 49; 129 | CL = 50; 130 | CM = 51; 131 | CN = 52; 132 | CO = 53; 133 | CR = 54; 134 | CU = 55; 135 | CV = 56; 136 | CW = 57; 137 | CX = 58; 138 | CY = 59; 139 | CZ = 60; 140 | DE = 61; 141 | DJ = 62; 142 | DK = 63; 143 | DM = 64; 144 | DO = 65; 145 | DZ = 66; 146 | EC = 67; 147 | EE = 68; 148 | EG = 69; 149 | EH = 70; 150 | ER = 71; 151 | ES = 72; 152 | ET = 73; 153 | EU = 74; 154 | FI = 75; 155 | FJ = 76; 156 | FK = 77; 157 | FM = 78; 158 | FO = 79; 159 | FR = 80; 160 | GA = 81; 161 | GB = 82; 162 | GD = 83; 163 | GE = 84; 164 | GF = 85; 165 | GG = 86; 166 | GH = 87; 167 | GI = 88; 168 | GL = 89; 169 | GM = 90; 170 | GN = 91; 171 | GP = 92; 172 | GQ = 93; 173 | GR = 94; 174 | GS = 95; 175 | GT = 96; 176 | GU = 97; 177 | GW = 98; 178 | GY = 99; 179 | HK = 100; 180 | HM = 101; 181 | HN = 102; 182 | HR = 103; 183 | HT = 104; 184 | HU = 105; 185 | ID = 106; 186 | IE = 107; 187 | IL = 108; 188 | IM = 109; 189 | IN = 110; 190 | IO = 111; 191 | IQ = 112; 192 | IR = 113; 193 | IS = 114; 194 | IT = 115; 195 | JE = 116; 196 | JM = 117; 197 | JO = 118; 198 | JP = 119; 199 | KE = 120; 200 | KG = 121; 201 | KH = 122; 202 | KI = 123; 203 | KM = 124; 204 | KN = 125; 205 | KP = 126; 206 | KR = 127; 207 | KW = 128; 208 | KY = 129; 209 | KZ = 130; 210 | LA = 131; 211 | LB = 132; 212 | LC = 133; 213 | LI = 134; 214 | LK = 135; 215 | LR = 136; 216 | LS = 137; 217 | LT = 138; 218 | LU = 139; 219 | LV = 140; 220 | LY = 141; 221 | MA = 142; 222 | MC = 143; 223 | MD = 144; 224 | ME = 145; 225 | MF = 146; 226 | MG = 147; 227 | MH = 148; 228 | MK = 149; 229 | ML = 150; 230 | MM = 151; 231 | MN = 152; 232 | MO = 153; 233 | MP = 154; 234 | MQ = 155; 235 | MR = 156; 236 | MS = 157; 237 | MT = 158; 238 | MU = 159; 239 | MV = 160; 240 | MW = 161; 241 | MX = 162; 242 | MY = 163; 243 | MZ = 164; 244 | NA = 165; 245 | NC = 166; 246 | NE = 167; 247 | NF = 168; 248 | NG = 169; 249 | NI = 170; 250 | NL = 171; 251 | NO = 172; 252 | NP = 173; 253 | NR = 174; 254 | NU = 175; 255 | NZ = 176; 256 | OM = 177; 257 | PA = 178; 258 | PE = 179; 259 | PF = 180; 260 | PG = 181; 261 | PH = 182; 262 | PK = 183; 263 | PL = 184; 264 | PM = 185; 265 | PN = 186; 266 | PR = 187; 267 | PS = 188; 268 | PT = 189; 269 | PW = 190; 270 | PY = 191; 271 | QA = 192; 272 | RE = 193; 273 | RO = 194; 274 | RS = 195; 275 | RU = 196; 276 | RW = 197; 277 | SA = 198; 278 | SB = 199; 279 | SC = 200; 280 | SD = 201; 281 | SE = 202; 282 | SG = 203; 283 | SH = 204; 284 | SI = 205; 285 | SJ = 206; 286 | SK = 207; 287 | SL = 208; 288 | SM = 209; 289 | SN = 210; 290 | SO = 211; 291 | SR = 212; 292 | SS = 213; 293 | ST = 214; 294 | SV = 215; 295 | SX = 216; 296 | SY = 217; 297 | SZ = 218; 298 | TC = 219; 299 | TD = 220; 300 | TF = 221; 301 | TG = 222; 302 | TH = 223; 303 | TJ = 224; 304 | TK = 225; 305 | TL = 226; 306 | TM = 227; 307 | TN = 228; 308 | TO = 229; 309 | TR = 230; 310 | TT = 231; 311 | TV = 232; 312 | TW = 233; 313 | TZ = 234; 314 | UA = 235; 315 | UG = 236; 316 | UM = 237; 317 | US = 238; 318 | UY = 239; 319 | UZ = 240; 320 | VA = 241; 321 | VC = 242; 322 | VE = 243; 323 | VG = 244; 324 | VI = 245; 325 | VN = 246; 326 | VU = 247; 327 | WF = 248; 328 | WS = 249; 329 | XX = 250; 330 | YE = 251; 331 | YT = 252; 332 | ZA = 253; 333 | ZM = 254; 334 | ZW = 255; 335 | } 336 | --------------------------------------------------------------------------------